How to create a Search Results page in Oxygen

Updated on Feb 13, 2023

This tutorial provides the steps to create an Oxygen template for displaying the search results.

We are going to display the search string that the user searched for, the results and a search form so the user can perform another search.

Step 1

Create a template in Oxygen and make sure to apply it to “Search Results” under “Other”.

Set a template priority (or order) higher than what’s set for your Archives template (if present) so this template gets used vs the Archives one.

You might want to inherit from a “Main” template that contains your header, an Inner Content element and the footer.

Step 2

Edit the template.

Add a Section containing a Code Block.

Add another Section having Easy Posts, a Heading and a Search Form (under WordPress).

Select the first Section and apply your desired background, text color and make any other styling adjustments.

In my test site, I’ve assigned a class of page-header to the Section, and to this class set Text Color as #fff, the Background Color as #5c258d, and added this Custom CSS:

background: -webkit-linear-gradient(to right, #5c258d, #4389a2); /* Chrome 10-25, Safari 5.1-6 */
background: linear-gradient(to right, #5c258d, #4389a2); /* W3C, IE 10+/ Edge, Firefox 16+, Chrome 26+, Opera 12+, Safari 7+ */

for the gradient.

Select the Code Block element inside this Section.

PHP & HTML:

<h1>Search results for: 
<?php echo esc_html( get_search_query( false ) ); ?>
</h1>

If you want to show the number of search results returned, use this code: https://pastebin.com/raw/C0T5LMVD (Source).

Select the Easy Posts element in the second Section. You may want to change the preset to your desired layout. I’ve left everything at default. Make sure that WP Query is set to default.

Select the Heading element in the second Section and change the text to something like “Make another search:”.

That’s it!

Update: If you want to conditionally output a Section when there are no search results, follow this tutorial.


Posted

in

,

by

Tags:

Comments

18 responses to “How to create a Search Results page in Oxygen”

  1. Rey Avatar
    Rey

    Awesome tutorial Sridhar! Just what I was looking for! I appreciate also that you demonstrated gradient backgrounds with CSS.

    Quick question.. Is there a way to modify the number of entries per page? The default 5 is not enough for me, and when I start to use custom or manual, it goes pear shaped for me.

    What’s the best way to modify the number of entries per page?

    1. Sridhar Katakam Avatar

      number of entries per page just on the search results archive or generally in all archives?

  2. Mat Avatar
    Mat

    Excellent post – thanks.

    Search results page for PAGES would be really helpful too.

    Thanks again!

  3. trustedsamurai Avatar
    trustedsamurai

    Hi Sridhar,

    I’m using Relevanssi and have set it to index my CPT which contains information about scientific publications.

    When a search is performed, say on a keyword I know exists in a title I am taken to the search results page

    http://atrc.org.au/?s=baseline

    But the Easy Post seemed to display a lot of unrelated content. Even though I set it to the CPT of ‘Publications’. Ideally I don’t really want to limit the search results to a single CPT so I would want this page to display any type of results.

    Do you have any thoughts on this?

    Regards,

    John.

  4. Attila Avatar
    Attila

    Namaste dear Sridhar!
    Please provide us a Search results page for PAGES (or for pages and posts together), because this way the search string is searched only in the posts which is not enough for my projects.
    Thank you in advance!

    1. Sridhar Katakam Avatar

      _/_ Attila.

      WordPress search searches across both Posts and Pages by default.

      1. Attila Avatar
        Attila

        Dear Sridhar!

        It’s OK that WP searches across both posts and pages, but the search result page I created with the help of this tutorial shows only results found in posts…
        Mat wrote about the same wish below on October 5, 2018.

        1. Sridhar Katakam Avatar

          Just tested and I don’t have this issue.

          Search results show both posts and pages.

          Screenshot: https://d.pr/i/kdyl77

          You may want to contact Oxygen’s support if the issue persists.

          1. Attila Avatar
            Attila

            I contacted the support as you advised and when they logged in to my admin, it turned out that I entered all the headings and texts directly to Oxygen which WordPress search doesn’t index. So the solution was very simple, I had to copy-paste all the texts from Oxygen to WordPress editor for all my pages and Update them.

          2. Sridhar Katakam Avatar

            Yes.

            It is recommended to have the main Page and Post content in the WordPress editor, if possible.

  5. Giang Lê Hoàng Avatar

    Great tuts! I hope you can extend to make a complicated search with choices, dropdown..using ACF :V!

    Many thanks!

    1. Sridhar Katakam Avatar

      Can you provide more details of what should appear in the dropdowns? Do you want users to be able to search by a category that appears in a dropdown list?

  6. Julie Starling Avatar

    Thank you for this! I tried it and had to eliminate the “inner content” from the template and just put in the search parameters because leaving the “inner content” seems to call up inner content from pages or posts I don’t want there depending on what I “search for.” If I search for x, then perhaps innercontent from a page associated with that term comes up. If I search for “y” which has maybe one word use throughout my site, it will bring up the entire page (header builder, post content, footer) that has that one word in it, followed by the search results. If I eliminate the inner content section, of course I can’t use the template as a page builder but the search function works perfectly. Admittedly, I’m probably NOT using WordPress and Oxygen the way they supposed to be used if I’m getting this odd behavior. Furthermore, while I’m fairly confident in my HTML and CSS, I’m often stuck when it comes to wrapping my head around the WP functions and writing in php which often has me searching the web for quick code fixes or plugins for what i need. So in the end, thank you for this!

  7. gslweb Avatar
    gslweb

    How can I add a message for when there are no results for a certain keyword?

  8. […] condition can be used in conjunction with the How to create a Search Results page in Oxygen tutorial so that a message can be shown when there are 0 search […]

  9. coloursb Avatar
    coloursb

    This is great, thank you! How do I go about building this template out if I want to customize the results in any way (instead of use the default Eas Post query)? I want to group the search results by category.

Leave a Reply to WooCommerce in Oxygen – WPDevDesign Cancel reply

Your email address will not be published. Required fields are marked *