Home Forums General Issues Show posts by custom field : 'date_event'


Show posts by custom field : 'date_event'

  • Hello,
    I am French, so sorry if I make mistakes.
    I want to show only next month posts . I use the ACF plugin to indicate the date of the event. My code does not work, it displays all posts of the custom post type ‘sports’, not only next month posts. Someone can help me ?

          // date month + 1
          $date_next_month = (new DateTime)->modify('+1 months')->format('m');
          // parameters of $upcoming
          $args_upcoming = array(
            'post_type' => 'sports',
            'meta_key' => 'date_event',
            'orderby' => 'meta_value',
            'order' => 'ASC',
           'meta_query ' => array(
                'key' => 'date_event',
                'compare' => '=',
                'value' => $date_next_month,
          // $upcoming objet
          $upcoming = new WP_Query($args_upcoming);
          // the loop
            while ($upcoming->have_posts() ) {
                  $upcoming->the_post(); ?>
              <td><?php echo get_field('date_event');?></td>
              <td><?php echo the_title(); ?></td>
              <td><?php echo get_the_content() ?></td>
         <?php  }
Viewing 1 post (of 1 total)

The topic ‘Show posts by custom field : 'date_event'’ is closed to new replies.