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

Reply To: How to Max Length CustomField result to 100

Home Forums Product Support Forums Ajax Search Pro for WordPress Support How to Max Length CustomField result to 100 Reply To: How to Max Length CustomField result to 100

#30419
Ernest MarcinkoErnest Marcinko
Keymaster

Hi,

Well, the only way to do that is via custom coding, instead of using the advanced field, as there is no parameter to control that.

I constructed a custom code for you, which should help with that. Try adding it to functions.php in your theme/child theme directory. Before editing, please make sure to have a full site back-up just in case!

Change the $custom_field and $length variables according to your needs.

add_filter( 'asp_results', 'asp_c_field_to_desc', 10, 1 );
function asp_c_field_to_desc( $results ) {
	$custom_field = "field_name";
	$length = 100;
	
	// ------ DO NOT CHANGE BELOW ----------
	foreach ($results as $k=>&$r) {
		if ($r->content_type != "pagepost") continue;
		if ( function_exists('get_field') )
		  $meta_value = get_field( $custom_field, $id, true ); // ACF support
		else
		  $meta_value = get_post_meta( $id, $custom_field, true );
		// Modify the post title to add the meta value
		if ( !empty($meta_value) ) {
			$r->content .= wd_substr_at_word($meta_value, $length);
		}
	}
  
	return $results;
}