Support

Account

Home Forums ACF PRO Sub field repeater query

Helping

Sub field repeater query

  • ACF PRO 5.6.6
    —————
    Hello,
    In a project I need to display a CPT (programmation) related to another one (lieux).
    In Programmation, I have a repeater filed named les_representations and a subfield ‘lieu_de_la_representation’ (post object)
    this is my code

    <?php $id_post_origine=get_the_ID();?>
    <tr><td><strong>
        <a href="<?php echo the_permalink(); ;?>" title="<?php the_title_attribute(); ?>" target="_blank"><?php echo $id_post_origine?> <?php the_title(); ?></a></strong></td>
        <td><?php the_modified_date();?> à <?php the_modified_time();?></td>
        <td>
    
       
                           <?php 
    
    // args
    $args = array(
    'suppress_filters' => false,
    	'post_type' => 'programmation',
    	'meta_query' => array(
    		array(
    			'key' => 'les_representations_%_lieu_de_la_representation',
    			'value' => $id_post_origine,
    			'compare' => 'LIKE'
    		)
    	)
    );
    $the_query = new WP_Query( $args );
    ?>
    <?php if( $the_query->have_posts() ): ?>
    	<ul>
    	<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    		<li>
    			<a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
    		</li>
    	<?php endwhile; ?>
    	</ul>
    <?php endif; ?>
    
    <?php wp_reset_query();	 // Restore global post data stomped by the_post(). ?>     

    It doen’t display anything and i don’t understand why.
    Have you got any Idea ?

    Thanks a lot.

  • Hi @goushi

    Can you try following step 4 of this article: https://www.advancedcustomfields.com/resources/query-posts-custom-fields/

    Update: Since the changed behaviour of esc_sql() in WordPress 4.8.3, it is not easy to use the % character as a placeholder for the following search and replace, instead, we recommend that you use the $ character as shown below.

    That may be causing your issue ^

    Please let me know if that helps, or if we need to dig a bit deeper.

    Phil

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.