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 use custom taxonomy with pages. Basically a page has a "relevance" taxonomy, depicting who the page is relevant for. The pages are created in a hierarchy based on the departmental structure of the school district which the site is for. So say I'm on the alumni page, and I want to list all the child pages of educational services that are relevant, like how to get your transcripts.

I've tried the following two methods

<?php 
  $pages = get_pages( array( 'child_of' => '65','hierarchical' => 0, 'meta_key' => 'relevance', 'meta_value' => 'alumni' ) );
  foreach ( $pages as $page ) {
    echo $page->post_title;
  }
 ?>

and

<?php wp_list_pages( array( 'child_of' => '65', 'meta_key' => 'relevance', 'meta_value' => 'alumni') ); ?>

both display the child pages of 65 without the meta_key & meta_value properties, but once I had them I get nothing. I'm super positive the values are correct.

I've also tried..

'relevance' => 'alumni',

like you would in a query, but that doesn't work with these functions.

Any idea why this wouldn't work? The get_pages function lists meta_key & meta_value under usage and denotes that you have to set hierarchical to 0 which I did.

share|improve this question
    
If the answer below solved your problem, please accept it. –  mrwweb Oct 22 '12 at 14:23

1 Answer 1

up vote 3 down vote accepted

Custom taxonomies are not meta values, but rather their own thing. I don't think wp_list_pages() or get_pages() can query based on a taxonomy, so I'd recommend using WP_Query instead:

<?php
$relevant_pages_args = array(
    'post_type' => 'page',
    'posts_per_page' => -1,
    'post_parent' => 65,
    'tax_query' => array(
        array(
            'taxonomy' => 'relevance',
            'field' => 'slug',
            'terms' => 'alumni'
        )
    )
);

$relevant_pages = new WP_Query( $relevant_pages_args );

if( $relevant_pages->have_posts() ) : while( $relevant_pages->have_posts() ) : $relevant_pages->the_post(); ?>

    <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>

<?php endwhile; endif; wp_reset_postdata(); ?>
share|improve this answer
    
Sweet, I do this is it! Thank you! –  Tiffany Israel Oct 22 '12 at 18:11

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.