Home › Forums › General Issues › How to order by custom field then post date? › Reply To: How to order by custom field then post date?
You need to use clauses in your meta_query in order to combine ordering by meta values and post date. See the last code snippet in the orderby section https://codex.wordpress.org/Class_Reference/WP_Query
As far as ordering posts based on whether or not the post has an image or a gallery, that I don’t really know. There is nothing like this listed and I don’t know if any of the existing “compare” arguments will do this. I would probably create a true/false field and make the gallery or image field conditional base on the true/false field. I would then set the image field to required so that if the user selects to add image that image is required. Then I would order the posts by the true/false field in DESC order. Since the db value is 0/1, ordering them this way would put any with the field set to true at the top.
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!
🚀 This week’s session of ACF Chat Fridays dips into the preliminary results of our first ever user survey. Don’t miss it! https://t.co/3UtvQbDwNm pic.twitter.com/kMwhaJTkZc— Advanced Custom Fields (@wp_acf) May 9, 2023
© 2023 Advanced Custom Fields.