2

I am trying to update yoast focus keyphrase using the code below.

add_action( 'created_product_cat', 'ts_custom_woocommerce_placeholder', 10, 2 );
function ts_custom_woocommerce_placeholder( $post_id ) {
    $productname = 'test prduct'
    update_post_meta($post_id, '_yoast_wpseo_focuskw', $productname.' ecm');
    return true;
}

What am I missing here?

  • There are several problems here. To start with, update_post_meta "Updates a post meta field based on the given post ID." and here you do not seem to be updating a post, you are updating a WooCommerce product category term or not? – Tami Mar 28 '22 at 13:10
  • I am updating a category term. but I want to update _yoast_wpseo_focuskw as well – Danilo Credo Lu-ang II Mar 29 '22 at 01:14
  • OK, so if the meta '_yoast_wpseo_focuskw' is for category terms, and not for posts or CPTs, then I think I know how to help you, but you would have to first confirm that Yoast has this meta key for category terms. Let me know – Tami Mar 29 '22 at 10:41

0 Answers0