Autofill Term Name (product category) as Focus Keywords

#67539
  • Resolved Watch Teller
    Rank Math free

    Hi,

    Request two (2) code snippets to use term name (by product category and post category name) to autofill into focus keywords metabox.

    Thanks in advance.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hello,

    Thank you for contacting Rank Math today.

    Unfortunately there is no current feature/filter in Rank math to do so. You can use the following snippet that was used to auto-fill the keyword using tags. With the help of a developer, you can customize it to fit your situation.

    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){
    		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' );

    Hope it helps you. Thank you.

    Thanks!

    Tried, the post type change to “product” but not worked.

    Any other alternative.

    Thanks again.

    Hello,

    Let me check with the dev team if there is another alternative.

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello,

    We are so so sorry but we have no option of automating this.

    You have to put in the focus keyword manually.

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

    Noted and thanks

    Hi,

    We are glad to be of help.

    If you need help with anything else, please open a new support ticket here so we can help.

    We are always here for assistance.

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

The ticket ‘Autofill Term Name (product category) as Focus Keywords’ is closed to new replies.