Home Forums General Issues Display a field into a wp_query


Display a field into a wp_query

  • Hi there,

    I’m struggling to display a simple text field into a loop. Please find below my code :

    $args = array( 
      'post_type' => 'realisations',
      'posts_per_page' => 99
    $the_query = new WP_Query( $args );?>
    <div class="last-post-type portfolio-grid">
    	if ( $the_query->have_posts() ) : 
    	  while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
    	  	<div class="card item">
    	  		<div class="card_wrapper">
    			    <div class="card_thumbnail">
    			      <?php the_post_thumbnail('full'); ?>
    			    <div class="card_content">
    			      <h3><?php the_title(); ?></h3>
    			      <h5><?php the_field('realisation_sub'); ?>h</h5>
      	<?php endwhile; ?>
    	<?php endif;?>
    	// Restore original Post Data
    	wp_reset_postdata(); ?>

    the ‘realisation_sub’ field remains empty and I can’t figure out why.

    Thanks by advance for your help.

  • Ok, I found my mistake. If it could be useful to someone, don not forget to add , get_the_ID() to make it work.

    like so in my exemple
    <h5><?php the_field('realisation_sub'); ?>h</h5>


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

The topic ‘Display a field into a wp_query’ is closed to new replies.