Hello,
Thank you for contacting Rank Math support and we apologize for the inconvenience.
There’s a possibility that you’re getting this error because you’re ‘posts_per_page’ => -1
which attempts to revive all your posts all at once – which can slow down your site or cause errors if you have a lot of products.
However, you can limit the number of posts that you process each time by setting a limit on the posts like so:
'posts_per_page' => 100
You can then add an offset to the function as well to continue adding the focus keywords to newer posts. So, after changing the first 100 posts you add an offset of 100 to the function like so:
'offset' => 100
You can continue to increase the offset by 100 until it runs through all of the posts.
Each time you run the function, you can add 100 to the offset value like,
1st time : 'offset' => 0,
2nd time : 'offset' => 100,
3rd time : 'offset' => 200,
And so on…
I hope that helps.
Thank you.
but then will it retrieve all posts?? even the ones that have focus keyword
Hello,
Thank you for getting back to us.
Yes, it would retrieve all your products in badges of 100, but let me explain how this works.
The code will fetch 100 products at a time from your site and check if they have a focus keyword set. If not, it will use the product title as the focus keyword and update it. Specifically this line:
if (!get_post_meta($p->ID, ‘rank_math_focus_keyword’, true)) {
update_post_meta($p->ID, ‘rank_math_focus_keyword’, $title);
This way, you can avoid overloading your site or getting errors. You can repeat this process by changing the offset value in the code until all your products have a focus keyword. I hope this makes sense.
If you have any questions, please let me know.
Cheers!
hello the code breaks my website and brings a wordpress error unfortunately
Hello,
Thank you for getting back to us. We’re here to help you with any issue you might have with our plugin.
We can see that you have marked this ticket as resolved, we’re assuming that is a mistake – please let us know if this issue has truly been resolved, but if t hasn’t then we would need some more information from you to understand what’s causing the error on your site. Could you please tell us how you are inserting the code into your site? Are you using a plugin, a theme, or a custom function? Also, could you please share the exact code that you are using and the error message that you are getting? This will help us to diagnose the problem and find a solution faster.
To share screenshots with us, you can use Imgur, a free online image hosting service. Just upload your images to Imgur and copy the link that they provide. Then paste the link in your reply here.
Thank you for choosing Rank Math as your SEO plugin. We look forward to hearing from you soon.
hey it was markes as a mistake the issue is still there with the code
Hello,
Please share your website’s recent error logs so we can determine what’s causing the issue.
You can follow this guide to enable debugging in WordPress
https://wordpress.org/support/article/debugging-in-wordpress/ or you can get in touch with your web host, they will help you locate the log file.
We really look forward to hearing back from you. Thank you.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.