Home Forums General Issues How to filter posts by date picker ACF


How to filter posts by date picker ACF

  • Hi, ive been following one of the guides on here to try and order my custom post types named Events by date order which uses the ACF date picker but am having difficulties.

    If anyone could give me a pointer that would be really good.

    Heres what i have so far:

    $date = DateTime::createFromFormat('Ymd', get_field('date_picker'));
    echo $date->format('d-m-Y');
    $posts = get_posts(array(
    	'meta_key' => 'custom_order', // name of custom field
    	'orderby' => 'meta_value_num',
    	'order' => 'ASC'
    if( $posts )
    	foreach( $posts as $post )
    		setup_postdata( $post );
    		// ...
    	wp_reset_postdata(); // IMPORTANT - reset the $post object so the rest of the page works correctly
    // get results
    $the_query = new WP_Query( $args );
    // The Loop
    		<?php if( $the_query->have_posts()  ): ?>
            <?php while( $the_query->have_posts() ) : $the_query->the_post(); ?>
    			$attachment_id = get_post_thumbnail_id(); // attachment ID
    			$image_attributes = wp_get_attachment_image_src( $attachment_id,'full' ); // returns an array
    		<div class="post"> 
    		<table class="event-table-cont">
    		 <th rowspan="7" style="background-image: url('<?php bloginfo('template_directory'); ?>/imageResizer/imgresize.php?src=<?php echo $image_attributes[0]; ?>&h=200&w=800&q=95');
             background-size: cover;border-radius: 5px 0px 0px 5px;" ;="" width="100px" ;)=""></th>
    		  <th class="event-title pad-left"><a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
              <span class="alignright event-date"><?php $dateformatstring = "l d F"; $unixtimestamp = strtotime(get_field('date_picker'));echo date_i18n($dateformatstring, $unixtimestamp);
     		 <th rowspan="7"></th>
     		 <td  class="pad-left"><span class="meta">Event Type: <?php $terms = get_the_terms( $post->ID , 'training' ); 
                        foreach ( $terms as $term ) {echo $term_link.$term->name;} 
                    ?></span> <div class="dots"></div></td> 
       		 <td class="pad-left" style="font-size: 15px;"><?php echo get_the_events_excerpt(); ?></td>
      		 <td  rowspan="7" class="pad-left">
             <a href="<?php the_field('webinar_url'); ?>">Signup</a><span class="alignright" style="width: 100px; height: 55px;"><?php echo do_shortcode('[hupso]')?></span>
            <?php endwhile; ?>
    		<?php else: ?>
            <?php _e('None found.','example'); ?>
    		<?php endif; wp_reset_query(); ?>
Viewing 1 post (of 1 total)

The topic ‘How to filter posts by date picker ACF’ is closed to new replies.