Array

This topic contains 3 replies, has 2 voices, and was last updated by erdalc90 erdalc90 2 years, 2 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #27513
    erdalc90
    erdalc90
    Participant

    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.

    #27514
    erdalc90
    erdalc90
    Participant
    You cannot access this content.
    #27521
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi,

    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!

    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;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


    #27523
    erdalc90
    erdalc90
    Participant

    Thank you so much.

Viewing 4 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.