This is a follow-up to my question about mass-updating WordPress posts here:
How can I mass-update/save all WordPress posts and pages?
And it is in relation to the Rank Math SEO plugin:
https://wordpress.org/plugins/seo-by-rank-math/
The plugin is relying on actions in individual post edits/updates to trigger certain things. So the actions aren't applying to posts existing before the plugin was installed unless they are manually updated. With over 1500 posts and several dozen pages, doing this manually isn't feasible.
Note: Using the built-in WordPress mass-edit feature from the post list does not work to trigger these actions.
The remaining problem has to do with the plugin calculating SEO scores for each post based on the content and meta data already there. These scores should be displayed in a column on the post list screen and in the page list screen.
But no scores are showing up for posts and pages there before the plugin was installed because the calculations aren't triggered until a post edit screen is opened for each page or post. This is being generated once the edit screen is opened (not when the post or page is updated -- why the answer from my previous question fixed one problem but not this part).
Once the score is calculated, it's being put into a custom field which -- when the post is saved -- seems to be pulled into the post list screen to show the scores for each post.
The following code from user Gregory from my previous question does handle the post updating:
function update_all_posts() {
$args = array(
'post_type' => 'post',
'numberposts' => -1
);
$all_posts = get_posts($args);
foreach ($all_posts as $single_post){
$single_post->post_title = $single_post->post_title.'';
wp_update_post( $single_post );
}
}
add_action( 'wp_loaded', 'update_all_posts' );
But because it doesn't open the edit screen for each post, it isn't triggering the calculation. So no score is entered into a custom field before this saves an update.
What I need is some variation on this which would trigger that calculation as if the "edit" action was being called for each one before the update is saved. And I need to work for both pages and posts.
Any help would be greatly appreciated.
Thanks!