Home › Forums › Front-end Issues › Display Featured Items First › Reply To: Display Featured Items First
<?php
// query events order
$posts = get_posts(array(
'posts_per_page' => -1,
'post_type' => 'event',
'meta_query' => array(
'date_clause' => array(
'key' => 'start_date',
'compare' => 'EXISTS'
),
'feature_clause' => array(
'key' => 'featured',
'compare' => 'EXISTS'
)
),
'orderby' => array(
'feature_clause' => 'DESC',
'date_clause' => 'ASC'
)
));
if( $posts ): ?>
<div class="events-list">
<?php foreach( $posts as $p ): ?>
<div><h2><a href="<?php echo get_permalink( $p->ID ); ?>"><?php echo $p->post_title; ?></a></h2></div>
<div><?php the_field('start_date', $p->ID); ?></div>
<div><?php the_field('end_date', $p->ID); ?></div>
<?php endforeach; ?>
</div>
<?php endif; ?>
I have write the code like this and it’s working (is it correct?)
And Thank you very much.
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!
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 Privacy Policy. If you continue to use this site, you consent to our use of cookies.