Hi Nigel,
Thanks for the quick response.
If that layout is what the documentation was trying to portray then I got absolutely none of that from it, it is very confusing in the way it has been written up and the examples don't really do a good job of illustrating that. The layout I've been using has come from other support threads as it was the only way I could get results out of it, but now I'm guessing that it's only been partially working and the rest is operating on default options as it doesn't understand the parameters outside of an array.
However, this still hasn't got me much further really I'm afraid.
I tried it exactly as you suggested:
$token = toolset_get_related_posts(
$child_id,
'child_token',
array(
'query_by_role' => 'parent',
'role_to_return' => 'child',
'orderby' => 'title',
'order' => 'DESC',
'limit' => 1
)
);
and it returns nothing. Now I wasn't sure if you'd written up a full example or were just explaining the layout, so I reworked my code to use the formatting you've highlighted (note: I had to include all options sequentially, as leaving out the args caused it to fail) like so:
$token = toolset_get_related_posts(
$child_id,
'child-token',
array(
'query_by_role' => 'parent',
'limit' => 1,
'offset' => 0,
'args' => array(),
'return' => 'post_id',
'role_to_return' => 'child',
'order_by' => 'null',
'order' => 'DESC'
)
);
and it's exactly the same. Returns them in ascending order regardless.
Just to confuse things further, I've noticed weird behaviour with another of my uses of 'toolset_get_related_posts', where it doesn't even return them in an order that makes any sense whatsoever!
Here's the original code:
$classes = toolset_get_related_posts( $term, 'term-class', 'parent', 999, 0, array(), 'post_id', 'child' );
and the response it provides:
Array (
[0] => 1201
[1] => 1192
[2] => 1193
[3] => 1194
[4] => 1195
[5] => 1196
[6] => 1197
[7] => 1198
[8] => 1199
[9] => 1200
[10] => 1265
)
As you can see, for some bizarre reason it's returned 1201 at the start, out of sequence! This is not the order of post title, post date, or anything to do with the meta data!
If I rework the code into the structure you have mentioned:
$classes = toolset_get_related_posts(
$term,
'term-class',
array(
'query_by_role' => 'parent',
'limit' => 999,
'offset' => 0,
'args' => array(),
'return' => 'post_id',
'role_to_return' => 'child',
)
);
It again makes zero difference, with or without the order_by and order parameters.
So I can't even tell for sure having the extra parameters in an array is even making a difference at present as this works to return posts with a blank meta_value:
$single_classes = toolset_get_related_posts(
$term,
'term-class',
'parent',
999,
0,
array(
'meta_key' => 'wpcf-recurring-class-name',
'meta_value' => '',
'meta_compare' => '=',
),
'post_id',
'child'
);
And as you can see, the parameters are not in an array.
So I'm thoroughly confused as to this behaviour. Any thoughts?