How to add shortcode to the results content?
Displaying shortcode outputs on the live search results content field
1
add_filter( 'asp_results', 'asp_my_custom_shortcodes_in_results', 10, 4 );
2
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
3
foreach ($results as $k=>&$r) {
4
if ( isset($r->post_type) ) {
5
$r->content .= do_shortcode("[my_custom_shortcode]");
6
}
7
}
8
return $results;
9
}
Copied!
It is also possible to pass the post ID to the shortcode as a parameter if neccessary:
1
add_filter( 'asp_results', 'asp_my_custom_shortcodes_in_results', 10, 4 );
2
function asp_custom_link_results( $results, $search_id, $is_ajax, $args ) {
3
foreach ($results as $k=>&$r) {
4
if ( isset($r->post_type) ) {
5
$r->content .= do_shortcode("[my_custom_shortcode id={$r->id}]");
6
}
7
}
8
return $results;
9
}
Copied!
Last modified 21d ago
Copy link