Home › Toolset Professional Support › [Resolved] meta_query on toolset_get_related_posts does not work with radio button values
This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.
Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.
Sun | Mon | Tue | Wed | Thu | Fri | Sat |
---|---|---|---|---|---|---|
- | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | 10:00 – 13:00 | - |
- | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | 14:00 – 18:00 | - |
Supporter timezone: Asia/Kolkata (GMT+05:30)
Related documentation:
This topic contains 13 replies, has 2 voices.
Last updated by Minesh 3 years, 10 months ago.
Assisted by: Minesh.
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?
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
Hello. Thank you for contacting the Toolset support.
What if you try to use the meta_compare to equal to rather then Like.
For example:
'meta_compare' => '=',
Do you see it working?
Hi Minesh,
putting on '=' and putting the actual value does not yield results
$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 + 2 Bath + 1 Den', 'meta_compare' => '=', ], 'orderby' => 'title', 'order' => 'ASC', 'limit' => -1, 'return' => 'post_object', ], );
I also tried to comment out the args block just to see if the code works without it, and it is, so I think there is a problem with the args meta query
Can you please share admin access details and tell me where exactly you added the code you shared and where you are calling that code?
*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.
I have set the next reply to private which means only you and I have access to it.
Hi Minesh,
i'll setup the the access and will provide it to you asap
Ok fine.
I have set the next reply to private which means only you and I have access to it.
example url: hidden link
file to check template-parts/content-single-floorplan.php
sorry, I did not notice the form where you actually put the credentials, could you please make the next reply as private again?
I have set the next reply to private which means only you and I have access to it.
I'm not sure whats going on but I'm not able to login to wp-admin using the access details shared.
Note: FTP access working fine.
Can you please make sure that you send me working wp-admin access details.
I have set the next reply to private which means only you and I have access to it.
this reply is not private but I edited the details on the previous private message, I also tested it, and it worked. please check it out
Still - the shared admin access details not working.
I've also asked one of my colleague to double check if its working or not but for him as well its not working.
Please send me working admin access details.
I have set the next reply to private which means only you and I have access to it.
You made a mistake.
When I checked the custom field group "Floor Plan" that holds the field "Suite Type":
=> hidden link
The value for the "1 Bedroom" option is set as "1BR". You can verify that what value is assigned to what option from the above link and check the associated value assigned to each option.
So, I've just changed the value within your code from:
'meta_value' => '1 Bedroom',
To
'meta_value' => '1BR',
And when I visit the post that is assigned the "1 Bedroom" option:
=> hidden link
When I check the same post on the frontend I can see its displaying the results:
- hidden link
You just need to make sure that you should assign the correct meta_value of the option.
Hi Minesh,
Thank you for your help. Is there a way to use IN? like:
'args' => [ 'meta_key' => 'wpcf-fp-suite-type', 'meta_value' => array('1BR', '1BR+DEN'), 'meta_compare' => 'IN', ],
I need to group all types of 1br together (as well as 2br, and 3br)
As you can see with our post relationship API Doc for toolset_get_related_posts()
=> https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts
Only limited values are supported for meta_compare ('=' | 'LIKE').
So, IN is not an option.