I have a pretty extensive music collection and my friends are always borrowing my stuff. I would like to keep better track of my library so I'm building a sudo-checkout system using WP.

The collection was already in WP using terms to sort everything. The main taxonomies are artist, year released, label, and genre. I want to add a new taxonomy called whereisit. The post type used is called album.

Because of the way that other plugins interact with the site (I'm a music geek) I can't easily use post meta for inventory status term. If it matters at the moment I'm using Scribu's plugin to autogenerate taxonomy search fields.

The question:

How can I display a list of terms who's related posts also match another fixed term?

For example: Show a list of terms for artists who's whereisit term is ihaveit. If all of the artist's albums have an whereisit term of idonthaveit, do not display the artist term in the list.

Or more simply: If all of my albums by a particular artist are loaned out to someone else, don't display the artist's name in the Artist list.

Would something like this have to be done through wpdb? Filtering a loop is easy enough, but translating that to a list is over my head. :)

Edit: I replaced the terms inhouse with ihaveit, checkedout with idonthaveit, and the taxonomy named inventorystatus with whereisit for better clarity.

  • you lost me at "If the term inhouse is checkedout" – Bainternet Jun 3 '11 at 22:19
  • @Bainternet I simplified the term names, hopefully this easier to follow now. :) – m-torin Jun 5 '11 at 14:25
  • So you want a list of albums by artist that are ihaveit? – Bainternet Jun 5 '11 at 15:46
  • @bainternet yes, that is correct. – m-torin Jun 5 '11 at 20:16

if i understand correctly you want to get a list of albums (posts) of a specific artist(taxonomy) and that are have ihaveit term.

if so the its a simple query using tax_query:

$args = array(
    'posts_per_page' => -1, //get all
    'post_type' => 'album', 
    'tax_query' => array(
        'relation' => 'AND',
            'taxonomy' => 'artist',
            'field' => 'slug', 
            'terms' => array( 'artist-slug' )
            'taxonomy' => 'whereisit',
            'field' => 'slug',
            'terms' => array('ihaveit')
$query = new WP_Query( $args );
    //to your thing / loop here
  • You phrased what I am trying to accomplish correctly but were are taking different meaning from it. My hope with this ticket is to create a list of taxonomies in a select menu that could then be searched. Related WP functions might be for example (to display all taxonomy terms), use the_terms, get_the_term_list, or wp_list_categories. – m-torin Jun 6 '11 at 12:38

Your Answer

