This topic contains 3 replies, has 2 voices, and was last updated by erdalc90 4 years, 3 months ago.
- AuthorPosts
- May 23, 2020 at 7:44 am #27513
Dear Ernest
I’m using ajax search pro a long time. I had a request for support a few years ago :). Now I have a question.
How can I show “ACF array fields” in search results. I tried to showing like product attribute array but nıt work. This is very important to me. I’m ready to pay for your support.
thank you, best regards.
May 23, 2020 at 8:03 am #27514You cannot access this content.May 23, 2020 at 10:40 am #27521Hi,
The plugin should recognize some basic array structures in the custom field values, and will print them comma separated. This may require a custom code to parse and print correclty.
I would try this custom code variation first. Try adding this custom code to the functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!
Best,add_filter( 'asp_results', 'asp_custom_field_to_results', 10, 1 ); function asp_custom_field_to_results( $results ) { $custom_fields = 'alternate_color_name'; // Enter the custom field names, comma separated $field = 'content'; // 'title' or 'content' $position = 'after'; // 'before' or 'after' $delimiter = ' '; // character between the field value and the field $fields = explode(',', $custom_fields); foreach ( $fields as $custom_field ) { $custom_field = trim($custom_field); foreach ($results as $k=>&$r) { if ($r->content_type != 'pagepost') continue; if ( function_exists('get_field') ) $meta_value = get_field( $r->id, $custom_field, true ); // ACF support else $meta_value = get_post_meta( $r->id, $custom_field, true ); if ( is_array($meta_value) ) { $meta_value = implode(', ', $meta_value); } // Modify the post title to add the meta value if ( $meta_value != '' ) { if ( $field == 'title' ) { if ( $position == 'before' ) $r->title = $meta_value . $delimiter . $r->title; else $r->title .= $delimiter . $meta_value; } else { if ( $position == 'before' ) $r->content = $meta_value . $delimiter . $r->content; else $r->content .= $delimiter . $meta_value; } } } } return $results; }
Ernest Marcinko
If you like my products, don't forget to rate them on codecanyon :)
May 23, 2020 at 3:01 pm #27523Thank you so much.
- AuthorPosts
You must be logged in to reply to this topic.