Hello, I have this 3 custom posts that I want to search and filter, so far I have not found a good way to search.
event
-band (relationship, created using ACF)
-place (relationship, created using ACF)
band
-music_type(custom taxonomy, similar to posts categories, created using CTP UI)
place
-location (Radio Button, created using ACF, list of places)
Now, I would like to search all the events of a location and of a music_type.
Is this possible?
Maybe I’m doing something wrong or in the free version of ACF this is not an available functionality.
you need to code it custom with php if you want to build a complex search for your frontend
Relationship fields are stored as an array of post IDs, so you will need the ID of the place you want to search for.
A radio field holds a text value.
$meta_query = array(
// relationship field => ID values
array(
'key' => 'relationship_field_name',
'value' => '"'.$post_id.'"',
'compare' => 'LIKE'
),
// radio field
array(
'key' => 'radio_field_name',
'value => $location
)
)
First of all, thanks for your answer.
// relationship field => ID values
array(
'key' => 'relationship_field_name',
'value' => '"'.$post_id.'"',
'compare' => 'LIKE'
),
lets suppose that there is a posts with IDs 16, 161, 616 and the post that I want to search is 16, wouldn’t this search cause problems? By problems I mean giving wrong results back.
I also think that it is not a good practice to store the ids in a serialized array, so I’m working on a code that stores data adding each ID separated, but I would like to know your opinion. Thanks again John.
That is why there are double quotes around the post ID your are searching for. ACF saves the post IDs in the serialized array as strings.