Automatically Use the Post Title as the Focus Keyword code is breaking my site

#413578
  • Resolved linus linus jn
    Rank Math free


    /**
    * Function to automatically update the focus keyword with the post title
    */
    function update_focus_keywords()
    {
    $posts = get_posts(array(
    'posts_per_page' => -1,
    'post_type' => 'post' //replace post with the name of your post type
    ));
    foreach ($posts as $p) {
    update_post_meta($p->ID, 'rank_math_focus_keyword', strtolower(get_the_title($p->ID)));
    }
    }
    add_action('init', 'update_focus_keywords');

    every time I try to Automate the Insertion of Focus Keyword using the code above and uploading it on the function.php it’s breaking my website, How do we change that? Im using the WP bootstrap starter theme

Viewing 1 replies (of 1 total)
  • Anas
    Rank Math business

    Hello,

    Thank you for contacting Rank Math, and sorry for any inconvenience caused.

    Please limit the number of posts and see if that helps.

    You can limit the number of posts that you process each time is by setting a limit on the posts like so:

    'posts_per_page' => 100
    

    You can then add an offset to the function as well to continue adding the focus keywords to newer posts. So, after changing the first 100 posts you add an offset of 100 to the function like so:

    'offset' => 100
    

    You can continue to increase the offset by 100 until it runs through all of the posts.

    Each time you run the function, you can add 100 to the offset value like,

    1st time : 'offset' => 0, 
    2nd time : 'offset' => 100,
    3rd time : 'offset' => 200,
    
    And so on...

    Hope this helps solve your issues.

    Don’t hesitate to get in touch if you have any other questions.

    Hello,

    Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.

    If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.

    Thank you.

Viewing 1 replies (of 1 total)

The ticket ‘Automatically Use the Post Title as the Focus Keyword code is breaking my site’ is closed to new replies.