Add bulk product focus keyword

#115139
  • Resolved Shirtmixer Kontakt
    Rank Math free

    Hi!
    I’ve checked the forum and I’ve found a very useful code what I tried to use on my WooCommerce store.
    The code is working very well but I need a small modification.
    The code what I’ve found is here: https://support.rankmath.com/ticket/bulk-add-product-keyword/
    The modification what I would like that It will attach not only the product name in to the focus keyword but I can give 1-2 word extra also to this.
    For example if I created a product with ‘Blue car’ name then with this extension the focus keyword will be ‘Blue car’ but I would like to add for every product the extra name as ‘print’ and the end all of the product will finish with ‘print’ —> ‘Blue car print’

    I would like to ask your help in this because I’m not professional in php coding.

    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' );
Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for getting in touch with us.

    We don’t offer customized code and we usually recommend seeking assistance from a developer if you can’t make the code modifications yourself.

    That said, you can try the following and if it still doesn’t work, you may have to hire a developer to do this for you.

    
    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)." print"; // With this we get the product title and concatenate it to print
    		update_post_meta($p->ID,'rank_math_focus_keyword',$term);
    		
    	}
        
    }
    add_action( 'init', 'update_focus_keywords' );
    

    Hope that helps.

    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 ‘Add bulk product focus keyword’ is closed to new replies.