Tell us what you are trying to do?
I wanted to rework my related floorplans by filtering it with the 'fp-suite-type' field via the meta query argument. However, does not return any results when I add the meta query.
example code that does not return any result:
$oneBR = toolset_get_related_posts(
$parentFP[0], // get posts related to this one
'condo-floor-plan', // relationship between the posts
[
'query_by_role' => 'parent',
'role_to_return' => 'child',
'args' => [
'meta_key' => 'wpcf-fp-suite-type',
'meta_value' => '1 Bedroom',
'meta_compare' => 'LIKE',
],
'orderby' => 'title',
'order' => 'ASC',
'limit' => -1,
'return' => 'post_object',
],
);
just to check if the code works, I tried to change the meta key with another radio field:
...
'meta_key' => 'wpcf-fp-availability',
'meta_value' => 'Available',
'meta_compare' => 'LIKE',
...
and it returned results
Is there any documentation that you are following?
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Is there a similar example that we can see?
this usage example from the documentation // Retrieve books from a particular writer that are written in a selected language
// (here, the language is stored in a Types field "book-language").
// Order results by titles.
$books = toolset_get_related_posts(
// Post representing a writer (or post ID),
// to which the results should be related.
$writer,
// Relationship slug.
'book_authorship',
// Additional arguments.
[
// Specify the role to query by and to return.
// Notice that we can use "other" in this situation.
'query_by_role' => 'parent',
'role_to_return' => 'other',
// Search by a value of postmeta.
'args' => [
// Use a meta_key of a Types field,
// which by default uses the "wpcf-" prefix.
'meta_key' => 'wpcf-book-language',
'meta_value' => 'Czech',
'meta_compare' => 'LIKE',
],
// Ordering
'orderby' => 'title',
'order' => 'ASC'
]
);
What is the link to your site?
hidden link