skip to Main Content

After doing some digging on my WordPress site, I’m pretty confident that adding the string ‘&post_type=product’ to the end of a search URL changes an Elementor search to a WooCommerce search. I’m unsure, however, how to implement this change?

What I want to do is add some code to functions.php which checks if there is some ‘?s=’ substring in a URL and if there is one, it adds ‘&post_type=product’ at the end of the URL.

Could someone show me how this is done?

2

Answers


  1. Firstly Update your permalink and
    add
    Hope this will help you

    Login or Signup to reply.
  2. <?php
    function your_custom_function(){
        $string = isset($_GET['s'])?$_GET['s']:"";
        if($string == "your_string_name"){
            global $wp;
            $new_url = $wp->request."?s=".$string."&post_type=product";
        ?>
    <script type="text/javascript">
        document.location.href = <?= $new_url; ?>;
    </script>
        <?php
        }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search