1

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.

3

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(); ?>

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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