Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Checklist Field Displays as Array
This topic contains 9 replies, has 2 voices, and was last updated by Ernest Marcinko 8 years ago.
- AuthorPosts
- August 22, 2015 at 11:20 pm #5602
Hi,
I am using ACF for a custom field for a list, it is set up as a checkbox type.
I want to display those fields in the search so I used Advanced Description Field (default: {descriptionfield}) and set it up:{descriptionfield} – {my_checkbox_list}
But when it displays it shows just Array – how can I show the array’s content?
( I have taken off current site – but have attached an image of how it displays)
August 24, 2015 at 8:14 am #5610Hi!
I believe ACF runs a function through that array to display it, or uses some kind of code to parse through the array. It means that not the checkbox HTML is stored in the custom field, but some kind of array values, that are transformed into checkboxes.
You can ask the ACF author how the checkbox array is transformed into actual HTML checkboxes, then I might be able to suggest a customization or filter function to append the transformed code to the result list. It’s probably going to be some kind of function or a small snippet from the ACF plugin code.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
August 24, 2015 at 8:50 am #5614Ok I started a thread – see what happens – http://support.advancedcustomfields.com/forums/topic/checkbox-list-displaying-as-an-array-in-search/
August 24, 2015 at 9:06 am #5617Nice! Let me know if they reply, and I will proceed from there.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
August 26, 2015 at 9:42 am #5683Hi Ernest,
I got a function that can output the array –
$checkboxes = get_field('my_checkbox_list'); if( $checkboxes ){ $checkbox_string = implode(', ', $checkboxes); echo ' – ' . $checkbox_string; }
So now how can I hook into Search results.
Thanks
Neil-
This reply was modified 8 years, 1 month ago by
neilgee.
August 26, 2015 at 10:49 am #5690Nice. First of all you need to change back the Advanced description field option to the default {descriptionfield} because we are doing a different solution.
Then, I put together a filter, which parses through each result and gets the ‘my_checkbox_list’ field as per suggested on ACF support forums. Then it’s appended to the description:
add_filter( 'asp_results', 'asp_checkbox_to_results', 1, 1 ); asp_checkbox_to_results( $results ) { foreach ($results as $k=>$v) { // Get the field $checkboxes = get_field('my_checkbox_list'); // Append if exists if( $checkboxes ){ $checkbox_string = implode(', ', $checkboxes); $results[$k]->content .= " - " . $checkbox_string; } } return $results; }
Hopefully it will work.
Best,
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
August 27, 2015 at 3:43 am #5692Hi,
No unfortunately didn’t work – so I set {descriptionfield} only in advanced desc. field and added function/action to functions.php but results did not show check list values – just the title field.-
This reply was modified 8 years, 1 month ago by
neilgee.
August 27, 2015 at 8:55 am #5694Hi!
If the normal description is showing, then the “if ( $checkboxes ) …” part of the code is not executed. I think the ACF get_field() function needs a post ID as well. Try this modification of their suggestion:
add_filter( 'asp_results', 'asp_checkbox_to_results', 1, 1 ); asp_checkbox_to_results( $results ) { foreach ($results as $k=>$v) { // Get the field $checkboxes = get_field('my_checkbox_list', $v->id); // Append if exists if( $checkboxes ){ $checkbox_string = implode(', ', $checkboxes); $results[$k]->content .= " – " . $checkbox_string; } } return $results; }
-
This reply was modified 8 years, 1 month ago by
Ernest Marcinko. Reason: fix
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
September 10, 2015 at 5:07 am #5845Apologies for the delay in getting back to you but this works great! – just had to prefix the function with function
Many thanks
September 10, 2015 at 10:28 am #5847You are welcome!
Indeed, I made a syntax error there.
For future reference the correct code:
Best,add_filter( 'asp_results', 'asp_checkbox_to_results', 1, 1 ); function asp_checkbox_to_results( $results ) { foreach ($results as $k=>$v) { // Get the field $checkboxes = get_field('my_checkbox_list', $v->id); // Append if exists if( $checkboxes ){ $checkbox_string = implode(', ', $checkboxes); $results[$k]->content .= " – " . $checkbox_string; } } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
-
This reply was modified 8 years, 1 month ago by
- AuthorPosts
You must be logged in to reply to this topic.