This website uses cookies to personalize your experience. By using this website you agree to our cookie policy.

Reply To: Distance Filters

#27645
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Those look like a serialized array fields, not texts unfortunately. This is only possible to print via custom code, and even then it can be problematic.

Based on this tutorial, I would recommend using the code below for starters.
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 = 'address_field'; 	        // 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 );
		$meta_value = maybe_unserialize($meta_value);	
		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;
}