admin管理员组

文章数量:1313143

Hi i have created a custom search with the following query. But the query is not working when i add multiple values to the post_type filed, the search is not giving me any results? did you have the same problem and how did you managed to resolve it? Im using woocommerce. this query only works with one value on the post_type i don't know what is wrong here ?

$args = array(
            's' => $searchterm,
            'post_type' => array( 'product','post', 'page'),
            'posts_per_page' => $max_posts_per_page,
            'orderby'   => 'date',
            'paged' => $paged
        );
        
        $the_query = new WP_Query($args);

Hi i have created a custom search with the following query. But the query is not working when i add multiple values to the post_type filed, the search is not giving me any results? did you have the same problem and how did you managed to resolve it? Im using woocommerce. this query only works with one value on the post_type i don't know what is wrong here ?

$args = array(
            's' => $searchterm,
            'post_type' => array( 'product','post', 'page'),
            'posts_per_page' => $max_posts_per_page,
            'orderby'   => 'date',
            'paged' => $paged
        );
        
        $the_query = new WP_Query($args);
Share Improve this question edited Dec 3, 2020 at 22:34 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Dec 3, 2020 at 12:07 Wilmar AriasWilmar Arias 1111 bronze badge 1
  • register same taxonomy for multiple post types. use same name/slug/etc. "my_one_taxonomy" and then register it for all post types. – Zaheer Abbas Commented Dec 3, 2020 at 12:33
Add a comment  | 

1 Answer 1

Reset to default 0

Hi i found my my problem it was polylang that causes the problem i need to add sopport for products to polylang settings so my fast fix was just to add 'lang'=> '' because my site is only in English at this moment.

<?php $args = array(
            's' => $searchterm,
            'post_type' => array( 'product','post', 'page'),
            'posts_per_page' => $max_posts_per_page,
            'orderby'   => 'date',
            'paged' => $paged,
            'lang'=> ''
        );

本文标签: I have problems with the search query using multiple post types