Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This might be complicated to explain and I don't know if there is a solution to that!?

I have a custom-post-type named "wr_event" and a hierarchical custom-taxonomy named "event_type". The custom-post-type has a meta-box for event_date and all posts associated with this post-type are sorted by this event_date. I have one special condition in my loop to query if the event_date has already taken place - in that case it's not shown but only listed in my archives.

Just like you can use wp_list_categories() I wrote a custom function that lists all taxonomy-terms exactly the same way.

And now my question:

When I use my custom wr_list_taxonomy() function it lists all taxonomies that have a post associated with it. Just like wp_list_categories() lists only the categories that have a post associated with it. If there would be a taxonomy-term that doesn't have posts it wouldn't be listed.

I wonder if it's somehow possible to "exclude" a taxonomy-term or simply not list it if all posts associated with it have an event_date that has already taken place.

Sounds complicated right?

So I have this function that works like a charm.

function wr_list_taxonomy($taxonomy, $orderby, $hierarchical) {
    $show_count   = 0;
    $pad_counts   = 0;
    $title        = '';

    $args = array(
      'taxonomy'     => $taxonomy,
      'orderby'      => $orderby,
      'show_count'   => $show_count,
      'pad_counts'   => $pad_counts,
      'hierarchical' => $hierarchical,
      'title_li'     => $title
    );

    return wp_list_categories( $args );
}

It lists all terms and only lists them if posts are in them. However I have posts ("events" in my case) in all taxonomy-terms, but have terms whose events are all over.

And if the "events" in a term are all over (and therefore the term-page doesn't list anything as I wrote above because I filter them by todays date) I don't want this function wr_list_taxonomy() to print this term.

Is that somehow possible?

share|improve this question

1 Answer 1

up vote 0 down vote accepted

It sounds like you're looking for wp_get_object_terms() which takes an array of post IDs, a taxonomy, and some optional arguments to determine what to return.

So, you'd use get_posts() to query future events, build an array of IDs, and then pass that array to wp_get_object_terms().

share|improve this answer
    
Awesome, perfect. Worked like a charm! –  mathiregister May 10 '12 at 6:53

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.