Home › Forums › General Issues › Use ACF taxonomy to Query
I have a page that throws a loop of a custom post Type (stores), I created a taxonomy (store_the_genre) which is divided in Men, Women, Children for the type of clothing, I want to know how to use the Post Query to post the genre
//Protect against arbitrary paged values
$testMe = get_field('store_the_genre');
$paged = ( get_query_var( 'paged' ) ) ? absint( get_query_var( 'paged' ) ) : 1;
if(have_posts() ):
$args = array( 'post_type' => 'store',
'posts_per_page' => 11,
'paged' => $paged,
'meta_key' => 'store_client_type',
'tax_query' => array(
array(
'taxonomy' => 'style',
'field' => 'slug',
'terms' => $style,
),
array(
'taxonomy' => 'bgenre',
'field' => 'term_id',
'terms' => $testMe,
),
),
'meta_query' => array(
'relation' => 'AND',
array(
'city_clause' => array(
'key' => 'store_city',
'value' => $villeshow,
'compare' => 'IN'
),
),
),
);
$loop = new WP_Query( $args );
while($loop->have_posts()): $loop->the_post();
Possibly something like:
<?php
$testMe = get_field('store_the_genre'); //assume this is returning a term ID?
global $wp_query;
$paged = get_query_var('paged') ? get_query_var('paged') : 1;
$args = array(
'post_type' => 'store',
'posts_per_page' => 11,
'paged' => $paged,
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'style',
'field' => 'slug',
'terms' => $style,
),
array(
'taxonomy' => 'store_the_genre',
'field' => 'term_id',
'terms' => $testMe,
),
),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => 'store_city',
'value' => $villeshow,
'compare' => 'IN',
),
),
);
$query = new WP_Query( $args );
if( $query->have_posts() ) :
while( $query->have_posts() ): $query->the_post(); ?>
<p><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </p>
<?php endwhile;
wp_reset_postdata();
else :
echo 'No stores found';
endif;
It depends if your store_the_genre taxonomy is a single value/multi value and returning the ID?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.