0

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.

2
  • Have you checked the real values of your custom fields in DB table? Commented Sep 1, 2013 at 21:31
  • @iEmanuele Thanks for the reply. Can you run me through the steps for doing that? I'd use phpMyAdmin I assume? Commented Sep 2, 2013 at 1:39

1 Answer 1

0

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/

2
  • 1
    You've just linked back to this question... please provide details of the solution instead of just a link post Commented Jan 15, 2014 at 6:31
  • @bungeshea Oops, sorry! I just corrected the link above. See Jonathan's accepted answer at the bottom. Commented Jan 15, 2014 at 14:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.