Home › Forums › Product Support Forums › Ajax Search Pro for WordPress Support › Shortcode in customfield soes not show up in results › Reply To: Shortcode in customfield soes not show up in results
I just had to remove {pricemonth} from the Advanced Description Field.
Two more questions:
1.] The shortcode shows fine, but now I have no control over where it shows up in the results box. I am fine with the placement now, but interested to know how to let it show elsewhere, for instance right in the box etc.
2.] I would like to put another shortcode ( availability ) in an other customfield. I tried the same code you provided with another extra custom field name, that does not work.
I tried this, but then it only shows the second customfield
—–
add_filter( ‘asp_results’, ‘asp_custom_field_to_results’, 10, 1 );
function asp_custom_field_to_results( $results ) {
$custom_field = ‘pricemonth’; // Enter the first custom field name
$custom_field = ‘availability’; // Enter the second custom field name
$field = ‘content’; // ‘title’ or ‘content’
$position = ‘before’; // ‘before’ or ‘after’
$delimiter = ‘ ‘; // character between the field value and the 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 = do_shortcode($meta_value);
// Modify the post title to add the meta value
if ( !empty($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;
}
————–
-
This reply was modified 7 years, 2 months ago by
ckworld.