Imported posts need resaving before showing readability score
-
Hi there,
I import WooCommerce products using WP All Import (and the WP All Import – Yoast WordPress SEO Add-On is activated). However, I need to resave all products manually in order to get a readability score and in order to show a correct breadcrumb. That has been OK, but the store is growing and now hundreds of products can be uploaded at once. Therefore, I am wondered whether it is possible to call the necessary hooks by code? I have tried calling the wp_update_post function and doing the save_post action. However, that does not set the readability score for the products.
Can you help me further?
function resave_unresaved_products() {
// Check if the specific URL parameter exists and has the correct value
if (get_query_var('resave_unresaved_products') === 'true'){
// Arguments to query only posts that do not have the _yoast_wpseo_content_score meta field
$args = array(
'post_type' => 'product',
'numberposts'=> -1,
);
$products = get_posts($args);
if ($products){
echo count($products) . ' products need resaving.<br>';
foreach ($products as $product){
//Method 1 tried:
$product->post_title = $product->post_title . '';
wp_update_post($product);
//Method 2 tried:
do_action('save_post', $product->ID, $product, true);
echo '<br>Resaved product: ' . $product->ID . ' - ' . $product->post_title;
}
} else {
echo 'No posts needs resaving.';
}
}
}
// Hook the function to the 'wp_loaded' action
add_action('wp_loaded', 'resave_unresaved_products');
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Imported posts need resaving before showing readability score’ is closed to new replies.