Home Forums Front-end Issues wp_query order by custom field


wp_query order by custom field

  • Hello all,

    I have create a custom taxonomy named Campaigns.

    Each campaign contain a number of custom post type, Offer.

    Each offer is belong to a custom post type named Restaurant. There has a Post Object field for select which restaurant the offer is belong to in Offer custom field group.

    I would like to know how can I only use wp_query() is good enough to get a group of offers and ordered by the restaurant post title?

    Thank you.

  • You cannot get a list of one post type ordered by a value of another post type. This is not possible use WP_Query.

    To do this any value you want to order by must be a value for the posts that you want to order.

    What this means is that when you save a post you must use an acf/save_post action to copy the values you want to be able to order by from the other post type and save it as a meta value for the post being saved.

  • Thanks for your answer, it is very helpful for me to learn more about the use of ACF and WordPress.

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.