I have a requirement where i need to restrict wordpress search to pages listing only and disable products listing . In other words i wanted to replace post type in the search url from 'products' to 'page'. Any possible solution ?

  • It was solved as i uninstalled woo commerce plugin. Aug 2, 2019 at 5:56

1 Answer 1


There are better ways, but one easy way to achieve this if you wanted to customise the search results is to edit the search.php template and make the WP_Query a custom one:

$args = array(
    's' => get_search_query(),
    'post_type' => array('page'),

$search_query = new WP_Query($args);

if ( have_posts() ) :

    while ( $search_query->have_posts() ) : $search_query->the_post();
        // do stuff here



Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.