Bulk Add Product Keyword

#46479
  • Hello

    I want to ask if there is a way to mass add Focus Keyword from the product title. We have more than 800 products atm and all product titles are the focus keyword we want to work on.

    Best Regards
    Leonidas

Viewing 5 replies - 1 through 5 (of 5 total)
  • Todd
    Rank Math free

    Hi Leonidas,

    Thanks for getting in touch with us.

    You can check this solution we offered another user:
    https://support.rankmath.com/ticket/how-to-auto-setup-focus-keyword-as-tag-title/page/2/?view=all

    Note: We assume you have basic coding knowledge when you are to automate a task like this so our help in coding instructions is going to be limited.

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

    Hello.

    I’ve pasted the code given above in my function.php of my theme but nothing changed.
    Maybe i’m doing something wrong? I pasted this code and then updated a product.

    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){
    		$primary_term = get_post_meta($p->ID,'rank_math_primary_category', true);
    		$term = get_term($primary_term, 'category');
    		update_post_meta($p->ID,'rank_math_focus_keyword',$term->name);
    		
    	}
        
    }
    add_action( 'init', 'update_focus_keywords' );
    Alberto
    Rank Math business

    Hello,

    Thank you for contacting Rank Math today.

    You had to modify the previous code to fit what you need. I suppose you are using WooCommerce and also, you said you need the product titles as the primary focus keyword so you should do the following changes to the code:

    function update_focus_keywords() {
    	$posts = get_posts(array(
    	'posts_per_page'	=> -1,
    	'post_type'		=> 'product' // With this we get only the products (WooCommerce)
        ));
    	foreach($posts as $p){
    		$term = get_the_title($p); // With this we get the product title
    		update_post_meta($p->ID,'rank_math_focus_keyword',$term);
    		
    	}
        
    }
    add_action( 'init', 'update_focus_keywords' );

    Looking forward to helping you. Thank you.

    ​​​​​​

    Hello

    Thanks a lot Alberto! It worked like a charm!

    Todd
    Rank Math free

    Hello,

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

    If you don’t mind me 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 do 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 ‘Bulk Add Product Keyword’ is closed to new replies.