Support » Plugin: Ajax Search Lite » 2 Custom Fields in Search Results

  • Great Plugin!!

    My aim is to show 2 different custom fields for each search result that drops down. At the moment I use 1. Is there a way to add another field.

    See TicketYoda.com homepage for example.
    Thanks

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

    (@wpdreams)

    Hi,

    Well, you will need a custom code to do that, as the lite version back-end only allows 1 field.

    Use the following code in the functions.php file in your active theme directory:

    add_filter( 'asl_pagepost_results', 'asl_add_extra_cf', 1, 1 );
    function asl_add_extra_cf( $results ) {
      $meta_name = 'your_field'; // Change this to the meta name
      $delimiter = ' | ';       // The delimiter before the meta
      // -----------------------------------------------
      foreach ($results as $k=>$v) {
        $meta = get_post_meta($v->id, $meta_name, true);
        if ( !empty($meta) ) {
          $results[$k]->content .= $delimiter . $meta;
        }  
      }   
      return $results;
    }

    Change the $meta_name and the $delimiter variable to your needs 🙂 I hope this helps!

    Thread Starter adambeaumont1

    (@adambeaumont1)

    Thanks for the help, it works perfectly.

    I will upgrade to the PRO version because this is by far the best search plugin on the market. Keep up the good work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘2 Custom Fields in Search Results’ is closed to new replies.