Display category archives in search results

Home Forums Product Support Forums Ajax Search Pro for WordPress Support Display category archives in search results

This topic contains 5 replies, has 2 voices, and was last updated by Ernest Marcinko Ernest Marcinko 6 years, 11 months ago.

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #5477
    enoversum
    enoversum
    Participant

    Hi there,

    already recommended and implemented (each unique licenses bought by my customers) your plugin on quite a few projects now, and still happy with it!

    One question from a customer arose that I am not sure the settings pages for sources truly answer, so I thought you might as well quickly help us out on that matter. Is it possible to include category archive pages into search results? I just give you an example:

    The post „Ajax Search Pro rocks“ appears in a category „Recommendations“. The category obviously does not have „Ajax“ in its title, nor is it featured on its description. However, my customers want that when searching for „Ajax“, both the post and the category archive appear as search result. Is that possible? Or do the current settings only refer to indexing category titles, term names, tags etc.?

    Any help appreciated, and thanks in advance 🙂

    Eno

    #5497
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Eno!

    It’s nice to hear from you again, I hope you are doing fine 🙂

    Sorry I didn’t answer today, I had a few priority issues to solve first. I’ve read through your request and I think I might be able to put together a snippet to append the categories to the result list.
    I just got home, so I’m done for today, just wanted to let you know that I have read your ticket. Tomorrow morning, when I’m back I will most likely post a solution, I have something on my mind, it might work, just need to test it first on my test servers 🙂

    Best,
    Ernest Marcinko

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


    #5500
    enoversum
    enoversum
    Participant

    Hey Ernest,

    good you still remember me :). There were actually some smaller things I was still waiting for, but it got lost a bit within other projects meanwhile (one thing was the ability to re-name CPT from singular to plural, so it doesn’t say „Page“ or e.g. „Recipe“, but „Pages“ and „Recipes“ on search result groups – don’t know if you ever considered this actually 🙂 ).

    Okay, no rush, but thanks for considering catering a solution for the latest challenge with category archives, will gladly wait for something you come up with.

    How have you been lately? Any holidays in sight? Warm summer, around your place too :)? I am just about to drift to Norway for two weeks with my family, starting on Friday. A bit of refreshment since Berlin is super hot these days :).

    All the best

    Eno

    #5501
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi again!

    Actually I have never though of the plural forms. I’m going to re-work grouping options within 2 updates, so I might as well add some kind of option to define singular-plural forms.

    So, I have tried something and it work on my test server. The good news is, that it does not need any modification in the search code, so it’s kind of update proof. However this will only work with non-grouped result list. Add the following code to the active theme functions.php file:

    add_filter( 'asp_pagepost_results', 'asp_add_categories_to_results', 1, 1 );
     
    function asp_add_categories_to_results( $pageposts ) {
      $category_res_arr = array();
    
      foreach ($pageposts as $k=>$v) {
     
        // Get the post categories
        $post_categories = wp_get_post_categories( $pageposts[$k]->id );
        $cats = "";
     
        // Add each category as result to the result array
        foreach($post_categories as $c){
            $cat = get_category( $c );
            $new_res = new StdClass();
            $new_res->title = $cat->name;
            $new_res->content = "";
            $new_res->image = "";
            $new_res->author = "";
            $new_res->date = "";
            $new_res->link = get_category_link($cat->term_id);
            $category_res_arr[$cat->term_id] = $new_res;
        }                
      }
     
      // Merge the posts and the categories together
      return array_merge($pageposts, $category_res_arr);
    }

    This basically gets every category for each post and appends it at the end of the posts results array. It should handle duplicates, so each category should appear only once.

    I’m doing fine, thank you for asking 🙂 Actually, I’m going to Montenegro next wednesday for a week with my family. I can’t wait to get some rest from the computer. Norway sounds fantastic in these hot days. I’ve never been there, my sister once was, she said it’s a wonderful country. You will surely have a great time.

    Anyways, let me know if this code works for you, or if you need something else.

    Best,
    Ernest Marcinko

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


    #5631
    enoversum
    enoversum
    Participant

    Hi Ernest,

    sorry I didn’t reply earlier, got a bit hectic before we left for Norway. (And you should definitely go there, the landscape and the quietness is really stunning!)

    As it happens, my customers would have needed both the grouped search results and the display of archive pages. Would that in any way be possible with maybe another small modification of sorts :)?

    All the best and thank you so much for your quick and friendly help as usual :).

    Eno

    #5777
    Ernest Marcinko
    Ernest Marcinko
    Keymaster

    Hi Eno!

    Sorry for the long delay, I got lots of tickets and mails to take care of. Well, there is no quick fix for grouped results in this case, because in the recent version I changed up a few things, and it’s a bit more difficult to access and modify the grouped results array correctly.

    I’ll have a bit more time for development tomorrow morning, I will try to come up with a solid solution for you. There is definitely a solution, but this time I have to test it properly to avoid errors 🙂

    Best,
    Ernest Marcinko

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


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

You must be logged in to reply to this topic.