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: Articoli and one for my custom post type: pacchetti
    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:

    $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(); ?>
    <h2><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h2>
    <?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!