Forums › Forums › Search & Filter Pro › ACF / Post Meta Fields in current_query() Result
Tagged: acf, search data
- This topic has 3 replies, 3 voices, and was last updated 4 years, 2 months ago by Trevor.
-
Anonymous(Private) June 22, 2020 at 10:49 pm #249698
My S&F is entirely filtering on ACF fields as post meta results.
I’d like to display the selected search terms, however there seems to be a difference in how to get these vs more standard fields like category.
For example:
global $searchandfilter; $sf_current_query = $searchandfilter->get(1526)->current_query(); echo $sf_current_query->get_field_string("_sft_category");
gives the expected result, but changing the argument in the third line to be a custom field using the name that appears in the url bar(?_sfm_work_type=26-%2C-27&_sfm_industries=14-%2C-15) doesn’t give any results, even though the filter works fine.
global $searchandfilter; $sf_current_query = $searchandfilter->get(1526)->current_query(); echo $sf_current_query->get_field_string("_sfm_industries");
Is there a change in method to get those fields?
Trevor(Private) June 23, 2020 at 5:44 am #249704You first need to find out where the data is, and to do so you need to examine the filter array:
<?php global $searchandfilter; $sf_current_query = $searchandfilter->get(1526)->current_query()->get_array(); echo '<pre>',print_r($sf_current_query,true),'</pre>'; ?>
This will print that array to the screen. From that you would need to use code LIKE this:
echo $sf_current_query['_sft_category']['active_terms'][0]['name']
This would echo out the first Category term. You will need to write a similar line, for example:
echo $sf_current_query['_sfm_industries']['active_terms'][0]['name']
-
AuthorPosts