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!
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.