Loop through multiple custom taxonomy terms and display posts for a custom post type

If you look at your var_dump, near the end, you will see the actual query being used.

SELECT wp_posts.* 
FROM wp_posts 
INNER JOIN wp_term_relationships 
ON (wp_posts.ID = wp_term_relationships.object_id) 
WHERE 1=1 
AND ( wp_term_relationships.term_taxonomy_id IN (93) ) 
AND wp_posts.post_type IN ('post', 'page', 'attachment') 
AND (wp_posts.post_status="publish" 
    OR wp_posts.post_author = 1 
    AND wp_posts.post_status="private") 
GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC

You haven’t told the query to look in your custom post type. Notice the wp_posts.post_type IN ('post', 'page', 'attachment')? This is obvious in your code as well, but I nonetheless didn’t notice until I saw the var_dump 🙁

You need to alter your query so that you are searching your custom type, and your ‘taxonomy’ query is off.

$wp_query = new WP_Query( 
    array(
       'post_type' => $post_type, // should be 'links', correct?
       $taxonomy => $term->slug,
       'posts_per_page' => '-1'
    )
);

Or…

$wp_query = new WP_Query( 
    array(
       'post_type' => $post_type, // should be 'links', correct?
       'tax_query' => array(
          array (
            'taxonomy' => $taxonomy,
            'field' => 'slug',
            'term' => $term->slug,
          )
       ),
       'posts_per_page' => '-1'
    )
);

I am sticking my neck out some but I think that will do it. I’d have to set up a lot of stuff in my database to actually test that– post type, terms, add some data, etc– but that looks right. If it is off, hopefully it isn’t off too badly.

You do realize this isn’t going to scale very well? With the nested loops and the multiple queries this is not very efficient, and could grind to a crawl if your taxonomy gets very big.

Reference: http://codex.wordpress.org/Class_Reference/WP_Query#Taxonomy_Parameters