Support » Plugin: Easy Primary Category » Get primary category on single post?

  • $categories = get_the_category();
    $category_id = $categories[0]->cat_ID;

    The above will give me the first category, but that’s not always the one I have marked as primary.

    How can I get the primary category on a single post (if that post is assigned to more than one category)?

Viewing 1 replies (of 1 total)
  • It’s saved as post meta. It can be retrieved with get_post_meta( $post_id, 'epc_primary_' . $enter_your_taxonomy_slug_here, true ); and will kick back the primary term id (if it exists).

Viewing 1 replies (of 1 total)
  • The topic ‘Get primary category on single post?’ is closed to new replies.