Here's a brief outline of the set-up:

"The Art" CPT is where all the art and art descriptions are uploaded. In this CPT you can choose the category (custom taxonomy) of the art--painting, jewelry, sculpture, etc. This allows me to have a page that displays all the art that's filterable with Isotope. I'm also sharing the taxonomies between the two CPTs.

"The Artist" CPT is where all the artist bios will go (the site will eventually have about 50 artists--which is why I created a CPT to manage them). In this CPT you can choose the category (custom taxonomy) of the artists name (it has a parent category of "The Artists") and I'm sharing The Art custom taxonomy too though I've seen no use for it yet.

What I want:

When you click onto the artists' page, which is single-the-artists.php--all artist data is being displayed with one page--the artists' name and bio is listed from "The Artist" CPT. Below their bios I'm trying to get all the art assigned to them under "The Art" CPT by Artist Name custom taxonomy.

So I have a taxonomy of and this is what I think I'll query with:

The Artists

-----Individual artist name

-----Individual artist name

-----Individual artist name

I know I need to get the current page taxonomy but I'm having a dickens of a time figuring out how to do that. I've tried get_children_terms, get_terms, wp_get_object_terms and nothing seems to get me where I need to go.

The query I'm currently using is pulling all the art but I want the art for that specific artist on the page at that time.

Here's my query:


$term_slug = get_query_var( 'the-art' );
$taxonomyName = get_query_var( 'art-category' );

$args = array(
    'post_type' => 'the-art',
    'order' => 'rand',
    'posts_per_page' => -1,
    $taxonomyName => $term_slug

$art_work = new WP_Query(); 
while ($art_work->have_posts()) : $art_work->the_post(); ?>

// do loop stuff here

<?php endwhile; wp_reset_postdata(); ?>

TIA for any help that you can offer.

This is the final piece in this pro-bono site and I want to be done with it. :)

2 Answers 2


Before I start, you should not use capital letters in your names, and also, don't use hyphens, the correct way is to separate words with underscores

What you are trying to do doesn't work. Do a var_dump() to get the available query variables on your single page

?><pre><?php var_dump($wp_query->query_vars); ?></pre><?php

You will see that the following are invalid

$term_slug = get_query_var( 'the-art' );
$taxonomyName = get_query_var( 'art-category' );

I don't know of any means to get the taxonomy from a term name, so this you will need to hardcode and you will also need to do a check to see if a post term belongs to the taxonomy.

To get the post terms, you can make use of one of the following

I would most probably also make use of a proper tax_query, the reason is, the way you are doing it will not work if you have more than one term.


I ended up having to use the Post 2 Post plugin to get this to work. Apparently WP isn't great with creating relationships at the moment, so plugin help is needed. After much searching, this is the solution I came across and I've no affiliation with the creator of the plugin...just happy that it solved my problem.

A description from the WP Plugin page:

This plugin allows you to create many-to-many relationships between posts of any type: post, page, custom etc. A few example use cases:

  • manually curated lists of related posts
  • post series
  • products connected to retailers etc.

Additionally, you can create many-to-many relationships between posts and users. So, you could also implement:

  • favorite posts of users
  • multiple authors per post
  • etc.

The documentation can be found here: https://github.com/scribu/wp-posts-to-posts/wiki

It was as easy as adding a few lines to my functions file then doing a WP_Query for the relationship.

  • Would be nice if you can link to the plugin page, add a short description of what is does and state your affiliation :-). Glad you got your problem solved Oct 12, 2014 at 16:33
  • OK, your answer was flagged as low quality, I'm not going to vote to delete it right now. Please file an edit with my requirements above, otherwise your answer might get removed by the community, and don't forget to accept your own answer Oct 12, 2014 at 16:40
  • 1
    I updated as requested. Oct 12, 2014 at 16:41
  • Great, thanks, Everything came through in one go :-) Enjoy. BTW +1 for updating Oct 12, 2014 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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