Automating keyword

#430094
Viewing 5 replies - 1 through 5 (of 5 total)
  • Hello,

    Thank you for contacting Rank Math support, and sorry for any inconvenience that might have been caused due to that.

    You can follow this filter code here and simply replace the post_type to ‘product’.

    Can you please confirm if you have already done so?

    Looking forward to helping you on this one.

    Thank you for the quick response.

    I have done that and it still doesn’t reflect any changes.

    This is exactly what I have used

    /**
    * Function to automatically update the focus keyword with the post tags
    */
    function update_focus_keywords()
    {
    $posts = get_posts(array(
    ‘posts_per_page’ => 100,
    ‘post_type’ => ‘product’ //replace post with the name of your post type
    ));
    foreach ($posts as $p) {
    $keywords = [];
    if (get_the_tags($p->ID)) {
    foreach ((get_the_tags($p->ID)) as $tag) {
    $keywords[] = strtolower($tag->name);
    }
    update_post_meta($p->ID, ‘rank_math_focus_keyword’, implode(“, “, array_unique($keywords)));
    }
    }
    }
    add_action(‘init’, ‘update_focus_keywords’);

    Hello,

    Please use the code given below:

    /**
     * Function to automatically update the product focus keyword with the product category
     */
    function update_product_focus_keywords()
    {
        $products = get_posts(array(
            'posts_per_page' => 100,
            'post_type' => 'product' //replace post with the name of your post type
        ));
        foreach ($products as $p) {
            $keywords = [];
            if (get_the_terms($p->ID, 'product_tag')) {
                foreach(get_the_terms($p->ID, 'product_tag') as $term) {
                    $keywords[] = strtolower($term->name);
                }
                update_post_meta($p->ID, 'rank_math_focus_keyword', implode(", ", array_unique($keywords)));
            }
        }
    }
    add_action('init', 'update_product_focus_keywords');
    

    Hope this helps. Let us know if you need any other assistance.

    Yes it worked perfectly, thank you so much! Katie

    Hello,

    We are super happy that we have addressed your concern. If you have any other questions in the future, know that we are here to help you.

    If you don’t mind us asking, could you please leave us a review (if you haven’t already) on https://wordpress.org/support/plugin/seo-by-rank-math/reviews/#new-post about your overall experience with Rank Math? We appreciate your time and patience.

    If you have another question in the future, please feel free to create a new forum topic, and it will be our pleasure to assist you again.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)

The ticket ‘Automating keyword’ is closed to new replies.