Tell us what you are trying to do?
Get children ordered by the value from intermediate post
Is there any documentation that you are following?
Is there a similar example that we can see?
What is the link to your site?
Hello,
Yes, it is possible, see our document:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Function toolset_get_related_posts() has a parameter "orderby_role":
string orderby_role: Name of the role by which ordering should happen. If no value is provided, the first value from the 'role_to_return' argument will be used.
ok, I've got it working, however not for secondary language using wpml.
$result = toolset_get_related_posts($series_id,
$relationship_slug,
array(
'query_by_role' => 'parent', // origin post role
'role_to_return' => 'child', // role of posts to return
'return' => 'post_object', // return array of IDs (post_id) or post objects (post_object)
'limit' => 999, // max number of results
'offset' => 0, // starting from
'args' => array(
'meta_key' => 'wpcf-priority',
'meta_value' => '%',
'meta_compare' => 'LIKE',
), // Additional query arguments
'orderby' => 'meta_value_num',
'orderby_role' => 'intermediary',
'order' => 'ASC',
'need_found_rows' => false, // also return count of results
));
I assume you are going to order the result by a custom field "wpcf-priority" of intermediate post type.
I have tried it in my localhost, in your case, you need to do these:
1) Translate all three post types: parent, child and intermediate post types
2) Setup your PHP codes to query the intermediate posts, for example:
'role_to_return' => 'intermediary', // role of posts to return
3) in the loop of variable $result, get the child post ID by intermediary post ID
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
then use intermediary post ID to display the child post information
I did it in a different way
1. I get children without sorting
2. Get intermediary post and meta_data for each one, create a dictionary myDict[meta_data] = child
3. ksort(myDict)
Of cause meta-data wpcf-priority must be uniq which is a case for me.
Thanks anyway.
Yes, it is possible with your way, does it work for you? if not, have tried the solution I mentioned above?
https://toolset.com/forums/topic/is-it-possible-toolset_get_related_posts-orderby-meta_value-in-intermediate-post/#post-1777045
Please let me know if you need more assistance for it, thanks
My issue is resolved now. Thank you!