Links
Comment on page

How to add shortcode to the results content?

Displaying shortcode outputs on the live search results content field
add_filter( 'asp_results', 'asp_my_custom_shortcodes_in_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
foreach ($results as $k=>&$r) {
if ( isset($r->post_type) ) {
$r->content .= do_shortcode("[my_custom_shortcode]");
}
}
return $results;
}
It is also possible to pass the post ID to the shortcode as a parameter if neccessary:
add_filter( 'asp_results', 'asp_my_custom_shortcodes_in_results', 10, 4 );
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
foreach ($results as $k=>&$r) {
if ( isset($r->post_type) ) {
$r->content .= do_shortcode("[my_custom_shortcode id={$r->id}]");
}
}
return $results;
}