Support

Account

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.