Question

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.

Was it helpful?

Solution

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',
        array(
            'taxonomy' => 'artist',
            'field' => 'slug', 
            'terms' => array( 'artist-slug' )
        ),
        array(
            'taxonomy' => 'whereisit',
            'field' => 'slug',
            'terms' => array('ihaveit')
        )
    )
);
$query = new WP_Query( $args );
while($query->have_posts())
{
    $query->the_post();
    //to your thing / loop here
}
Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top