Skip Navigation

[Resolved] Customizing WordPress Search Results Page

This support ticket is created 3 years, 1 month ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 9:00 – 12:00 -
- 13:00 – 18:00 13:00 – 18:00 13:00 – 18:00 14:00 – 18:00 13:00 – 18:00 -

Supporter timezone: America/Jamaica (GMT-05:00)

This topic contains 7 replies, has 2 voices.

Last updated by Shane 3 years, 1 month ago.

Assisted by: Shane.

Author
Posts
#2195833
search-results.PNG

Can you tell me how I customize the built-in WordPress search results page. For example:

hidden link

Please note you won't be able to access that URL without modifying your hosts file. I've attached a screenshot for further reference. Thanks, and I apologize if this is covered in documentation somewhere - I couldn't seem to find anything on the subject.

- Aaron

#2196179

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Screenshot 2021-10-14 at 2.16.50 PM.png

Hi Aaron,

Thank you for getting in touch. The wordpress default search page is actually an archive. In order to customize it you will need to create a custom archive at Toolset -> WordPress Archives and then select Search Results. See Screenshot

Please let me know if this helps.
Thanks,
Shane

#2196227

Thanks - that was helpful. So I have Relevanssi Premium installed on the site, which offers a lot of features such as ordering search results, highlighting search words that hit, etc. How do I take advantage of these features when using a custom search archive?

- Aaron

#2196845

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Aaron,

Happy I was able to assist.

How do I take advantage of these features when using a custom search archive?

Given that this is a Relevanssi then I wouldn't be equipped to say how to do this. My best recommendation would be to get in touch with the relevanssi support team to see how best they can assist with this one.

Thanks,
Shane

#2198913

If I could push just a little further, Toolset requires Relevanssi be installed, so I thought you may have some more insight into this. I'm assuming when using text-based search filters in Toolset that it uses Relevanssi's engine? I can reach out to them about the highlight features, but I would assume that the search logic would at least work as configured in Relevanssi. Do you know of any way to order results by Relevanssi's default order-by? Looks like by using a Toolset content template that you're forcing it to use something else, like title, date, etc.?

- Aaron

#2199793

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Aaron,

In terms of the highlight feature they would be better equipped to handle that as it would've needed to support custom templates.

Do you know of any way to order results by Relevanssi's default order-by?

When I checked relevanssi they only have 2 ordering which is by post date and by relevance. The relevance attribute is a default ordering attribute of wordpress archives so you should be able to write a custom hook to overwrite the Toolset ordering.

So something like this.

add_action( 'pre_get_posts', 'my_change_sort_order'); 
    function my_change_sort_order($query){
        if(is_archive()):
         //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
           //Set the order ASC or DESC
           $query->set( 'order', 'ASC' );
           //Set the orderby
           $query->set( 'orderby', 'relevance' );
        endif;    
    };

Thanks,
Shane

#2199939

Thanks - I'll take a look at using that custom code. My only question is regarding the note on needing to change is_archive() if it's a custom post type. In this particular example, the archive is the "search results" archive, so would include all post types that allow being included in global searches. Would this part of the code need to change?

- Aaron

#2200025

Shane
Supporter

Languages: English (English )

Timezone: America/Jamaica (GMT-05:00)

Hi Aaron,

My only question is regarding the note on needing to change is_archive() if it's a custom post type.

You can perhaps add the is_search() parameter as well to determine if its an archive and a search archive like below.

add_action( 'pre_get_posts', 'my_change_sort_order'); 
    function my_change_sort_order($query){
        if(is_archive() && is_search()):
         //If you wanted it for the archive of a custom post type use: is_post_type_archive( $post_type )
           //Set the order ASC or DESC
           $query->set( 'order', 'ASC' );
           //Set the orderby
           $query->set( 'orderby', 'relevance' );
        endif;    
    };

Thanks,
Shane