Home › Forums › General Issues › 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:
<?php
$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(); ?>
<?php
$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">
<tr>
<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);
?></span></th>
<th rowspan="7"></th>
</tr>
<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>
<tr>
<td class="pad-left" style="font-size: 15px;"><?php echo get_the_events_excerpt(); ?></td>
</tr>
<tr>
<td rowspan="7" class="pad-left">
</br>
<a href="<?php the_field('webinar_url'); ?>">Signup</a><span class="alignright" style="width: 100px; height: 55px;"><?php echo do_shortcode('[hupso]')?></span>
</td>
</tr>
</table>
</div>
<?php endwhile; ?>
<?php else: ?>
<?php _e('None found.','example'); ?>
<?php endif; wp_reset_query(); ?>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
ACF PRO’s Flexible Content field allows you to create smaller pieces of UI and compose them into whole flexible patterns. In our latest article, we show how to use it to create swappable site sections and integrate it all in a theme.https://t.co/ZRocH8oJSp
— Advanced Custom Fields (@wp_acf) January 24, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.