WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How do I modify the loop to show only posts of a specific custom taxonomy value? (4 posts)

  1. gendem
    Member
    Posted 3 years ago #

    Hi there,

    I have registered a custom taxonomy using the codex example pretty much exactly as presented, and that seems to have worked: everything shows up where it should, and so on.

    By way of example, assume that the custom taxonomy is called "color" and it have a the values "red" and "green". I'm now at the point where I want to code the equivalent of saying,

    "Show me each post (up to the default number per page) where the color is red."

    I am totally stumped as to how to do this. Nothing I have tried with query_posts() has worked, and I'm not sure where to try next.

    Can someone please illuminate this for me?

    ...Mike

  2. gendem
    Member
    Posted 3 years ago #

    For example:

    <?php
    query_posts( array( 'color' => 'red', 'showposts' => 10 ) );
    ?>

    returns everything regardless of the color it was assigned. From what I have read, this should have worked if executed before the loop. Is it something simple I have missed?

  3. gendem
    Member
    Posted 3 years ago #

    OK, I figured this out. For future reference, when you do the following

    query_posts( array( 'color' => 'red', 'showposts' => 10 ) );

    "red" should be the slug name, not the taxonomy value. This is what was tripping me up.

    ...Mike

  4. WP Jan
    Member
    Posted 3 years ago #

    Thanks Gendem. This actually helped! I had roamed these forums for 2 hours!

Topic Closed

This topic has been closed to new replies.

About this Topic