Hello,
Thank you for contacting Rank Math and bringing your concern to our attention. I’m sorry for any inconvenience this issue may have caused you.
I’ve checked your products, and indeed there are still 3,979 where the focus keyword is not set.
However, the filter you have to automate the focus keyword is set like this:
'posts_per_page' => 1
That line only updates 1 product. To apply the filter to all of your products in real-time, then you may need to set it to -1 like this:
'posts_per_page' => -1
About the scores, we don’t have a way to calculate them automatically. However, if you wanted to recalculate the scores in one go, then you can follow the steps in this link:
https://rankmath.com/kb/rank-math-status-and-tools/#recalculate-seo-score-for-posts
Hope that helps.
Thank you.
Hi.
Thanks for the reply.
It is.
The only problem is that no matter how much memory I allocate, and I have a generous package, I keep getting an error like “Allowed memory size…” So I put exact values, instead of -1, until I finished, then I recalculated the score for all .
But in the future, to do the job automatically, without consuming resources, how should I proceed? I mean, should I put a fixed value (let’s say 50 or 100 products – I don’t think there will be more than 100 products added to the feed at once)?
Or I did this (I didn’t test because I had solved it):
function update_focus_keywords() {
$args = array(
'post_type' => 'product',
'posts_per_page' => -1,
'fields' => 'ids',
);
$query = new WP_Query( $args );
$posts = $query->posts;
foreach ( $posts as $p ) {
// Checks if Rank Math keyword already exists and only updates if it doesn't have it
$rank_math_keyword = get_post_meta( $p, 'rank_math_focus_keyword', true );
if ( ! $rank_math_keyword ){
update_post_meta( $p, 'rank_math_focus_keyword', strtolower( get_the_title( $p ) ) );
}
}
}
add_action( 'init', 'update_focus_keywords' );
Hello,
In this case if the -1
value is exhausting your resources, then 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…
Hope that helps.
Thank you.
Thank you very much for the support.
Best regards
Hello,
Glad that helped.
Please feel free to reach out to us again in case you need any other assistance.
We are here to help.
Thank you.