Product Schema on Custom Post Type

#48013
  • Resolved Gareth Daine
    Rank Math free

    Hey Guys,

    We have a custom post type (Products) that we use for our affiliate product reviews (not e-commerce product listings) and we don’t want the product schema on these posts, so we have set it to be Article as default for all posts of this type.

    The problem is, on those that are legacy, we’re unable to change them to Article schema, as the only schema types that show under the drop-down on the post are ‘None’ and “Product’.

    I suspect an update needs to occur for this to be rectified, but in the meantime, is there any way to fix this so that we can set older posts to Article?

    Cheers

Viewing 1 replies (of 1 total)
  • Hello,

    Thank you for contacting Rank Math today.

    You can add the following code to your theme’s functions.php file to update the rich snippet type on all the posts on the product CPT:

    function update_snippet_type() {
    	$posts = get_posts(array(
    	'posts_per_page' => -1,
    	'post_type' => 'product' 
        ));
    	foreach($posts as $p){
    	
    		update_post_meta($p->ID,'rank_math_rich_snippet','article');
    		
    	}
        
    }
    add_action( 'init', 'update_snippet_type' );
    

    Once you have confirmed that the schema type has been updated after loading your WP, please delete the code.

    Remember to backup your site before using this update code.

    Looking forward to helping you. Thank you.

    ​​​​​​

    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 ‘Product Schema on Custom Post Type’ is closed to new replies.