Search Results: Dropdown Width & Show Categories

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Search Results: Dropdown Width & Show Categories

This topic contains 4 replies, has 2 voices, and was last updated by ShawnS52 ShawnS52 6 years, 11 months ago.

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #13316
    ShawnS52
    ShawnS52
    Participant

    Hello again, I think I have just 2 final questions on setting up the search to look the way I’d like.

    Through the element inspector in Chrome I’ve been able to adjust the width of the dropdown search results but I can’t figure out where to edit them in the plugin files. Here is an example of what I’d like to do, have the results dropdown width be 850px or a certain percentage: http://imgur.com/a/oxP62

    Second, is it possible to change the Advanced description field to show all of a post’s categories? I had found another ticket where you provided code to functions.php to show the tags, would it be similar for categories?

    Let me know if you would like me to submit these separately and thank you again for all the help!

    #13319
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi!

    1. I would not recommend making direct change to the plugin files, instead use this custom CSS code:

    div[id*=ajaxsearchprores] {
        width: 850px !important;
    }

    2. To display all categories, you will need a custom filter. Based on this knowledge-base example, this code should do the trick:

    add_filter( 'asp_results', 'asp_add_category_titles', 1, 1 );
     
    function asp_add_category_titles( $results ) {
      foreach ($results as $k=>$v) {
     
        // Get the post categories
        $post_categories = wp_get_post_categories( $results[$k]->id );
        $cats = array();
     
        // Concatenate category names to the $cats variable
        foreach($post_categories as $c){
            $cat = get_category( $c );
            $cats[] = $cat->name;
        }                
     
        // Modify the post title
        if ( count($cats) > 0 )
          $results[$k]->content  .= " ".implode(', ', $cats);
      }
     
      return $pageposts;
    }

    I have not tested this code, so please be careful!

    Best,
    Ernest Marcinko

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


    #13320
    ShawnS52
    ShawnS52
    Participant

    The results box css worked great!

    The Custom Filter didn’t do quite what I was looking for. For this section I would like the categories to be in place of the {descriptionfield}. Is that possible? Thanks!

    // Modify the post title
        if ( count($cats) > 0 )
          $results[$k]->content  .= " ".implode(', ', $cats);
      }
    #13324
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    You are welcome!

    To completely replace the content, just change this line in the code:

    $results[$k]->content  .= " ".implode(', ', $cats);

    ..to this:

    $results[$k]->content  = implode(', ', $cats);
    Best,
    Ernest Marcinko

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


    #13335
    ShawnS52
    ShawnS52
    Participant

    This worked fine, thanks!

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

You must be logged in to reply to this topic.