• Is it safe to hook into action asl_res_vertical_after_content to add custom content, and what would be the best way to do it, preferably accessing the current loop item?

    add_action(‘asl_res_vertical_after_content’, function( $r ) {

    Can we use $r as a parameter, as it is not explicitly passed when ajax-search-lite/includes/views/result.php does do_action('asl_res_vertical_after_content') ? Should we define global $r instead? Or is there a more elegant and documented way?

    I am aware of $s_options['showauthor'], $s_options['showdate'] and $s_options['showdescription'] the latter to show $r->content but I can’t use it and tweak the content as that would affect other parts of the blogs in unintended ways.

    Unfortunately, I did not find anything about my case in the documentation on https://documentation.ajaxsearchlite.com/advanced-options/title-and-content-fields?q=asl_res_vertical_after_content so I am hesitant to use an undocumented internal function without official API support.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author wpdreams

    (@wpdreams)

    Hi,

    I think for that use the asl_results hook. Unfortunately it is not documented (yet), but this is how to use it in a nutshell:

    add_filter( 'asl_results', 'asl_custom_link_results', 10, 1 );
    function asl_custom_link_results( $results ) {
    	$link = 'https://www.google.com/';	// Link to use, when not logged in
    	
    	// Parse through each result item
    	foreach ($results as $k=>&$r) {
    		/**
    		 * $r (stdClass object) {
    		 *      'id' -> Post or other result object (taxonomy term, user etc..) ID,
         *      'title' -> Result title
         *      'content' -> Result content
         *      'image' -> Result image URL
         *      'post_type' -> Result post type (if available)
         *      'content_type' -> Content type (pagepost, user, term, attachment etc..)
    		 * }
    		 **/
    		if ( !is_user_logged_in() )
    	  	$r->link = $link;
    	}
    
    	return $results;
    }

    In your case, you want to add whatever you need in the $r->content field within the results loop.

    Note, that this applies only to the live results list in the plugin results container. If you want to change the layout on the results page, then you may have to check the theme settings as well. Usually the excerpt is printed for the results page, so hooking into the the_excerpt could be a starting point.

    All the best,
    Ernest

    Thread Starter Ingo Steinke (openmindculture)

    (@openmindculture)

    It works! Thanks for your quick reply!

    Plugin Author wpdreams

    (@wpdreams)

    You are very welcome ??

    I will mark this as resolved now. Feel free to rate the plugin if you like it, it helps me a lot.

    All the best,
    Ernest

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Is it safe to hook into action asl_res_vertical_after_content?’ is closed to new replies.