Skip Navigation

[Resolved] Is there a way for to restrict a search field to ONLY display toolset data?

This support ticket is created 2 years, 4 months 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 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 1 reply, has 2 voices.

Last updated by Waqar 2 years, 4 months ago.

Assisted by: Waqar.

Author
Posts
#2239401

Tell us what you are trying to do?

Currently our site's search field returns all of the relevant toolset data as well as all of the wordpress data. Is there a way for me to create a new search interface that will only search data entered through toolset?

e.g. the client wants a product catalog search field and they don't want the employee directory to be included in the results. WordPress' default search returns both. Can the product catalog have a search field that only searches the product catalog?

in the example below, you can see that Maria White is returned along with the products that match the term "White"

Is there a similar example that we can see?

hidden link

What is the link to your site?

hidden link

Thanks in advance for any help

Gordon

#2239677

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Hi Gordon,

Thank you for contacting us and I'd be happy to assist.

If your goal is to limit WordPress search to bring in the results only from a specific post type "sku", you can use the "pre_get_posts" hook for this:
( ref: https://developer.wordpress.org/reference/hooks/pre_get_posts/ )


function search_filter($query) {
    if ( ! is_admin() && $query->is_main_query() ) {
        if ( $query->is_search ) {
            $query->set( 'post_type', 'sku' );
        }
    }
}
add_action( 'pre_get_posts', 'search_filter' );

The above code snippet can be included through either Toolset's custom code feature ( ref: https://toolset.com/documentation/adding-custom-code/using-toolset-to-add-custom-code/ ) or through the active theme's "functions.php" file.

Additionally, you can also optionally create a custom search archive using Toolset to have more control over the search fields and the search results design, as explained in this guide:
https://toolset.com/lesson-placement/lesson-placements-1621271-1622285/

regards,
Waqar

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.