How to Only Show Products in Search Page in WordPress

Posted on: April 30th, 2024
By: Tadeo Martinez

Add the following code to your functions.php

function custom_search_filter($query) {
    if ($query->is_search && !is_admin()) {
        $query->set('post_type', array('product')); // Replace 'product' with the name of your custom post type

Have any questions or comments? Write them below!

Leave a Reply

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