Skip to main content

Order Post by Relation Meta Field

Updated over a year ago

If you need to order your posts by metafield set up in Relations Meta, please, follow these steps:

1) Firstly, create an SQL query to pull the table that contains the relation meta field. For example

2) Proceed to Where (query clauses): here, we need to pull the posts that meet several conditions: a) they contain the same meta key; b) their parent_object_id equals the current post id

Example (listing of children is located on the Single Post page of the parent post):

3) Configure the ordering parameters:

Save the query.

4) Create another custom query - Posts Query type. Proceed to the "Post & Page" tab and use the "Query Results" macro on the Post In field:

5) Return to the "General" tab and configure ordering parameters:

6) Finally, apply the query to the listing:

Did this answer your question?