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.

I'm trying to create a template which will read a tag from the page, then display all the custom posts which share that tag. So for example, I have a custom post type called 'block', and a taxonomy on the block which is called 'appearson', and a tag of that taxonomy called 'products'.

I also have a products page, which shares the 'appearson' taxonomy, and also has the tag 'products'.

I want the products page template to read its appearson tag, then find the custom posts associated with that tag.

This is what I'm trying:

<?php $terms = get_the_terms( $post->id, 'AppearsOn' );?>


<?php
$args = array(
'post_type' => 'block'
'tax_query' => array(
array(
        'taxonomy' => 'appearson',
        'field' => 'id',
        'terms' => '$terms'
    )
  )
); ?>

<?php $the_query = new WP_Query( $args ); ?>

<?php while ( $the_query->have_posts() ) : $the_query->the_post();?>

It's not happy with this. Any pointers as to what I'm doing wrong? Blindingly obvious, I'm sure, but my 4 month old baby girl has stolen my brain.

Many thanks

Rob

EDIT

Actually ignore some of that. I'm now doing this:

<?php $terms = get_the_terms( $post->id, 'appearson' );?>


<?php
query_posts( array( 'post_type' => 'block', 'appearson' => $terms->name ) );
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>

So the bit I'm stuck on is getting 'appearson' => $terms to work. Any idea?

ta

Rob

Final edit:

Sorted it:

<?php $blocktaxonomy = wp_get_object_terms($post->ID, 'appearson');
$blocktaxonomy  = $blocktaxonomy [0];
query_posts( array( 'post_type' => 'block', 'appearson' => $blocktaxonomy ->name ) );

if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
share|improve this question
1  
could you post your solution as the answer and accept it? –  Tom J Nowell Apr 18 '12 at 10:41
    
Why not use the in-built taxonomy archive? –  Stephen Harris May 9 '12 at 15:59
add comment

2 Answers

@Stephen - at the time I was trying to create a list of a custom taxonomy from within another template. If I remember this piece correctly, I had created a custom post type called 'Portfolio' for a freelancer's website. When you clicked through to the single-portfolio.php page, I also wanted to show the custom taxonomy for that specific post type, so users could navigate through other portfolio pieces by taxonomy (in this case, 'copywriting', 'seo writing', 'etc'; he

share|improve this answer
add comment
up vote 0 down vote accepted

Solution:

<?php $blocktaxonomy = wp_get_object_terms($post->ID, 'appearson');
$blocktaxonomy  = $blocktaxonomy [0];
query_posts( array( 'post_type' => 'block', 'appearson' => $blocktaxonomy -    >name ) );

if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
share|improve this answer
add comment

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.