Take your website
To the next level
Discover our newly launched customization services and elevate your web projects to new heights.
Delegate tasks, save time, and unlock the power of professional WordPress outsourcing.

Okay
  Public Ticket #1865684
Filter Search Results
Closed

Comments

  • DesignicCreative started the conversation

    Hi there, 

    Just wondering if I can filter what the theme's search query returns. Ideally i'd like to use it exclusively to display shop/product results. 

  •  7,095
    Oliver replied

    Hi,

    You can use this filter:

    function wpse_search_filter( $query ) {
        if ( $query->is_search ) {
            $query->set( 'post_type', array('product') ); 
        return $query;
    }
    add_filter('pre_get_posts','wpse_search_filter');
    

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver

  • DesignicCreative replied

    thanks Gregor,

    Just a noob question though... where would I paste that code?

  •  7,095
    Oliver replied

    Hi,

    Add it to the functions.php of the child theme.

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver

  • DesignicCreative replied

    Hi Gregor, 

    I added the code to the end of the Functions.php file, but the search still only returns a post. 

    If you search for "wall" on the shop page you will see what I mean. http://mykitchen.nz/mykitchenshop/ 

    I was planning on using the site wide search for the shop exclusively, so having both the shop search bar and the menu search bar return products would be my ideal solution. Can you please help see where I've gone wrong?

  •  7,095
    Oliver replied

    Hi,

    pls. provide the wp-admin and FTP access

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver

  • DesignicCreative replied

    Hi there, 

    please use the user name: Temporary with PW: wD(PUrkm!WTL#pHlL@$7hzbP

    I don't have FTP access myself, though.

  •  7,095
    Oliver replied

    It's very dangerous to edit the php file via the wp editor, can you contact to your hoster and ask him the FTP access?

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver

  • DesignicCreative replied

    I do have CPanel which has all the site files there too if this works as an FTP. However, I don't feel comfortable handing out access to that as It's my clients account; I'm building the site for him. 

    If it's too complicated to explain, I may just have to purchase a Woo Plugin for searchability—unless I can make the general site search not exclusively return products, but at least include products?

  •  7,095
    Oliver replied

    Hi,

    The filter I gave you should work, I've tested it on our local install in order to find the problem I need access to the files. 

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver