Home › Forums › Front-end Issues › Custom fields from custom types through the location rules › Reply To: Custom fields from custom types through the location rules
Hi, thank you for your response..
I tell you what you ask me..
My custom post type is ‘pacchetto’ and i have two group for each post type. One for the wordpress posts: and one for my custom post type:
I want a query with CPT’s posts ‘pacchetto’ in sigle.php where return the posts when fields ‘zona_per_gli articoli’ = ‘zona-per-i-pacchetti’
I use the follow code:
<?php
$zone_articoli = get_field('zona_per_i_pacchetti');
$args = array(
'post_type' => 'pacchetto',
'meta_query' => array(
'key' => 'zona_per_gli_articoli',
'value' => $zone_articoli
);
$loop = new WP_Query($args);
while ( $loop->have_posts() ) : $loop->the_post(); ?>
<div>
<h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
</div>
<?php endwhile; wp_reset_postdata();?>
This code return me all posts from CPT ‘pacchetto’ and not filtering with fields. I think because i am in single.php and there are a rules for each post type
In effect if i write
echo $zone_articoli
it return the effective value, but if i write
$zone_pacchetti = get_field('zona_per_gli_articoli');
echo $zone_pacchetti;
don’t work (no value).
This last code work in single-pacchetto.php
I think i must merge the location rules for make my query with my fields…
Thank you so much!
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.