With Yoast SEO comes a functionality to set primary category among more than one category selection.
I am writing a piece of code where I need to fetch the primary category using the word-press DB tables.
I am unable to identify a way to query the DB to get only the primary category and not any other category associated with the post.
I am using wordpress version 4.5.3 with Yoast SEO installed.
2
Answers
I finally figured it out. The primary category as is a feature of the Yoast SEO plugin is available in wp_postmeta table. Each post's primary category is set against meta_key value "_yoast_wpseo_primary_category" with meta_value having the term_id from the wp_terms table for the primary category.
this query show for posts:
this query show primary category for products:
pay attention that
meta_key
value on above have different.