Get only primary category

Support General Get only primary categoryResolved

Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #38546
    RoderickRoderick
    Participant

    Hi,

    Is it possible to display only the primary category of a post? This is a feature I believe is added with the Yoast plugin. For example, I have a post with 2 categories:

    Colombia (Primary category)
    Hotels

    I'm using the following code in 'MB Views':

    {{ mb.get_the_term_list( post.ID, 'category', '', ', ' ) }}

    Hope you can help,
    Thanks Roderick

    #38549
    Long NguyenLong Nguyen
    Moderator

    Hi Roderick,

    You can follow this topic to know how to get Yoast primary term by a function of Yoast yoast_get_primary_term() then replace it with the WordPress function get_the_term_list()
    https://stackoverflow.com/questions/38800626/how-to-get-primary-category-set-via-yoast-seo-plugin-in-wordpress

    Hope that helps.

    #38630
    RoderickRoderick
    Participant

    Thanks for the advise! I didn't manage to exactly how you explained, as It's too difficult for me. But I got it to work via the extra code and shortcode 🙂

Viewing 3 posts - 1 through 3 (of 3 total)
  • You must be logged in to reply to this topic.