[resolved] Display post taxonomy (3 posts)

  1. GnorthernGnome
    Posted 1 year ago #


    I'm having a real issue trying to work out how to do this using WordPress, was wondering if someone could help.

    I have a custom taxonomy and custom page type set up for an events company. The taxonomy allows media, posts, pages etc. to be assigned to events, BUT I want to be able to display that taxonomy on the page?

    So I need to be able to return the taxonomy of a page (or multiple, if multiple are selected) and then display it.

    I'm also wanting to return a list of the last five blog posts linked to the same taxonomy, if anyone could help with that?

    Any help greatly appreciated!

  2. mrpritchett
    Posted 1 year ago #

    Just to make sure I understand, you want to display the current taxonomy(ies) of the current page (which is a custom page template), correct? If so, you can do something like this:

    $categories = get_terms( 'custom_taxonomy', array(
     	'orderby'    => 'count',
     	'hide_empty' => 0
     ) );'
    echo $categories;

    See this codex page for more examples and info on get_terms http://codex.wordpress.org/Function_Reference/get_terms.

    The second part is a simple loop with a query for the taxonomy term and limit the loop to 5 posts per page. Codex help: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters

  3. GnorthernGnome
    Posted 1 year ago #

    Thank you for your reply. I've had a play around with the code you provided and also read the get_terms documentation and between the two I've managed to get it working!

Topic Closed

This topic has been closed to new replies.

About this Topic