• Resolved teminet

    (@teminet)


    Hello, I just switched to Rank math and I like your plugin. However, until I installed rank math, there were so many pages that I couldn’t deal with keywords. That’s why I need keywords to be added automatically. For example: automatically define the page title as a keyword for individual product pages. The other need is for product categories pages. Automatically add the title of the product category as a keyword. In other words, titles are automatically added as keywords for both page types.

    I found a code in this direction.

    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) {
    update_post_meta($p->ID, ‘rank_math_focus_keyword’, strtolower(get_the_title($p->ID)));
    }
    }
    add_action(‘init’, ‘update_product_focus_keywords’);

    This code works but limits it to 100 products. The limit is -1, and when I do it I get a 500 error message.

    I would like to use your artificial intelligence tool, but I will not be able to use it because it does not have Turkish support. I’m waiting for your help. Kind regards.

Viewing 5 replies - 1 through 5 (of 5 total)
  • Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @teminet,

    Thank you for contacting Rank Math support.

    Please use the following filter:
    function update_focus_keywords() { $posts = get_posts(array( 'posts_per_page' => 100, 'offset' => 100, 'post_type' => 'product' // Replace post with the name of your post type )); 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->ID, 'rank_math_focus_keyword', true ); if ( ! $rank_math_keyword ){ update_post_meta($p->ID,'rank_math_focus_keyword',strtolower(get_the_title($p->ID))); } } } add_action( 'init', 'update_focus_keywords' );

    This code will add the focus keyword for 100 posts at once. Please make sure to increase the offset value by 100 each time you run the code.

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter teminet

    (@teminet)

    Hello, first of all, thank you very much. This code worked for individual product pages. But it didn’t work for product categories.

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @teminet,

    The previous code is only for the product post type, and it will not affect any other taxonomy such as the product categories.

    To automate this for your product categories please add this code as well:
    function update_focus_keywords_pcategories() { $args = array( 'taxonomy' => 'product_cat', 'orderby' => 'name', 'show_count' => 0, 'pad_counts' => 0, 'hierarchical' => 1, 'hide_empty' => 0 ); $all_categories = get_categories( $args ); foreach ($all_categories as $cat) { $rank_math_keyword = get_term_meta($cat->term_id, 'rank_math_focus_keyword', true); if (!$rank_math_keyword) { update_term_meta($cat->term_id, 'rank_math_focus_keyword', strtolower($cat->name)); } } } add_action('init', 'update_focus_keywords_pcategories');

    Hope that helps and please do not hesitate to let us know if you need our assistance with anything else.

    Thread Starter teminet

    (@teminet)

    You are awesome! Thanks.

    Plugin Support Rank Math Support

    (@rankmathsupport)

    Hello @teminet,

    We are super happy that we were able to address your concerns.

    Please do not hesitate to let us know if you need our assistance with anything else.

    Thank you.

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Rank math auto keywords’ is closed to new replies.