Adding shortcode or additional code to search results.

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Adding shortcode or additional code to search results.

This topic contains 1 reply, has 2 voices, and was last updated by

 
Keymaster
1 year, 2 months ago.

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #30190

    Participant

    Hi there.
    I have looked through the available filters and the plugin API and can’t seem to find what I’m looking for. If I have…please point me in the right direction 🙂

    I would like to add a short code, or regular PHP code, into the info that is included in each search result box. So when my searches come up I can have title, content, date, etc….and I see how to modify that through your panel… I want to add a shortcode for a bookmark app so as you scroll through results you can add them to a favorites list…a la the Netflix UI. I can’t see where to actually add a code snippet with a filter or through the control panel.

    Thank you for your time.

    Gabe

    #30197

    Hi!

    You are looking for the asp_results hook. That lets you make changes to the result items before they are printed.
    To run a shortcode, you can use this sample to start with:

    add_filter( 'asp_results', 'asp_custom_results_code', 10, 1 );
    function asp_custom_results_code( $results ) {
    
    	foreach ($results as $k=>&$r) {
    	  	$r-content = do_shortcode('[shortcode_name post_id=' . $r->id . ']') . $r-content;
    	}
    
    	return $results;
    }
    Best,
    Ernest Marcinko

    If you like my products, don't forget to rate them on codecanyon :)


Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.