Set rank_math_focus_keyword from custom field’s value

#263879
  • Resolved Shankar Thakur
    Rank Math free

    Hi,

    How can i set focus keyword on rank math automatically from custom field’s value after saving/publishing the post.

    My custom field id is: app_name

Viewing 5 replies - 1 through 5 (of 5 total)
  • Ankit
    Rank Math business

    Hello,

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

    With the general options of Rank Math, We do not have a way to get the focus keyword from a custom field. I believe this is something that would entail additional custom work with the plugin or some workaround since there exists a workaround of how to get a focus keyword from a title.

    We really look forward to helping you.

    Thank you.

    @ankit-singh I am waiting for the solution, hopefully i will get any snippets codes to do this.

    Hello,

    You would need to modify it via our filter. Please refer to this filter if you wish to update your post type’s focus keyword based from your custom field:

    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 ) {
            $ckeyword = get_field('app_name', $p->ID);
    
            update_post_meta( $p->ID, 'rank_math_focus_keyword', $ckeyword );
        }
    }
    add_action( 'init', 'update_focus_keywords' );

    I quickly edit this code from a placeholder code taken from this guide https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/ so you would need to further customize this filter code as per your preferences.

    Looking forward to helping you.

    @jeremy-4105 Thank You, My Problem is solved.

    Suggestion: Add this code to this guide article https://rankmath.com/kb/how-to-automate-the-insertion-of-focus-keyword/
    So Advance rank math users like me 😁 can find this easily

    Azib Yaqoob
    Rank Math business

    Hello,

    We are glad that helped you. We will pass on your suggestion to our content development team.

    Please don’t hesitate to contact us again if you need further assistance in the future.

    Thank you.

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

You must be logged in to reply to this ticket.