Home › Forums › Front-end Issues › Sort by custom field and publish date › Reply To: Sort by custom field and publish date
Thank you John, this solved my problem. I’m posting the updated code here for others to see. What i did is make the feature part of my meta_query and declare an index for “feature_clause” that just checks to see if the field exists. Then i added that to the “orderby” array including “date”, so both are sorted together. Here’s the updated query:
$review_args = array ( 'post_type' => 'customer_reviews', 'posts_per_page' => 20, 'post_status' => 'publish', 'meta_query' => array( 'relation' => 'AND', 'feature_clause' => array( 'key' => 'featured', 'compare' => 'EXISTS', ), ), 'orderby' => array( 'featured' => 'DESC', 'date' => 'DESC', ), 'fields' => 'ids' );
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!
Are you building WordPress sites with ACF and @BeaverBuilder, and wanted to use your ACF Blocks in both the block editor and Beaver Builder?— Advanced Custom Fields (@wp_acf) May 10, 2023
The BB team recently added support for using ACF Blocks in Beaver Builder. Check it out 👇https://t.co/UalEIa5aQi
© 2023 Advanced Custom Fields.