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 have the following:

custom post type: q-and-a
custom taxonomy: q_and_a_category
taxonomy terms: design, engineering, project-management

I'm creating three separate pages that filter the custom post types by their terms. I.e., one page for Design, one for Engineering, and another for Project Management.

I'm accomplishing this with three separate page templates, like this:

<?php

$args=array(
'post_type' => 'q-and-a',
'q_and_a_category' => 'design' //the slug for the custom taxonomy term
);
$my_query = null;
$my_query = new WP_Query($args);
if( $my_query->have_posts() ) {
while ($my_query->have_posts()) : $my_query->the_post();

?>

<?php the_title(); ?>

<?php endwhile; }?>

<?php wp_reset_query(); ?>

But I'm trying to create a single page template where the taxonomy term is inputted via a "select" menu that I've set up using advanced custom fields.

I tried following the ACF plugin tutorial for this, example 3:

http://www.advancedcustomfields.com/resources/how-to/how-to-query-posts-filtered-by-custom-field-values

Like this:

<?php 

// args
$args = array(
'numberposts' => -1,
'post_type' => 'q-and-a',
'meta_query' => array(
    'relation' => 'OR',
    array(
        'key' => 'q_and_a_category',
        'value' => '%design%',
        'compare' => 'LIKE'
    ),
    array(
        'key' => 'q_and_a_category',
        'value' => '%engineering%',
        'compare' => 'LIKE'
    ),
    array(
        'key' => 'q_and_a_category',
        'value' => '%project-management%',
        'compare' => 'LIKE'
    )
)
);

    // get results
$the_query = new WP_Query( $args );

// The Loop
?>
<?php if( $the_query->have_posts() ): ?>

<?php the_title(); ?>

<?php endif; ?>

<?php wp_reset_query();  // Restore global post data stomped by the_post(). ?>

When I try this, the page loads on the front end but no posts are displayed.

Any suggestions? Thanks in advance.

share|improve this question
    
Have you checked the real values of your custom fields in DB table? –  iEmanuele Sep 1 '13 at 21:31
    
@iEmanuele Thanks for the reply. Can you run me through the steps for doing that? I'd use phpMyAdmin I assume? –  dadra Sep 2 '13 at 1:39

1 Answer 1

up vote 0 down vote accepted

I also posted in the advanced custom fields forum and received the answer. It's simpler than I thought.

http://support.advancedcustomfields.com/forums/topic/help-with-query-posts-filtered-by-multiple-field-values/

share|improve this answer
    
You've just linked back to this question... please provide details of the solution instead of just a link post –  bungeshea_ Jan 15 at 6:31
    
@bungeshea Oops, sorry! I just corrected the link above. See Jonathan's accepted answer at the bottom. –  dadra Jan 15 at 14:38

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.