0
votes

Below code is combination of search result($query String) with added $args.

$all_num_normal (counted posts quantity) says its 5 posts as I expected. However, when I foreach title of posts, it shows only 3 titles. print_r also shows only 3 posts information.

When I search same keyword by regular search function, it shows 5 posts(its hit any of title, text, category name or meta value).

<?php
global $query_string;
$args = $query_string;
parse_str( $args, $args );
$args_normal = $args + array(
'posts_per_page' => -1,
'category_name' => $shop_name,
'category__not_in' => array( 3, 137, 571 ),
'meta_query' => array(
                    array(
                    'key'=> '2a',
                    'value' => array('2020-02-01' , $week),
                    'compare' => 'BETWEEN',
                    'type' => 'DATE',
                    ), 
                    ), 

);
echo '<pre>' . print_r( $args_normal, TRUE ) . '</pre>';
$query = new WP_Query($args_normal);
$all_num_normal = $query->found_posts;
?>

<?php
//Must be 5 titles, but its only 3 titles shown
$my_posts = get_posts($args_normal);
//print_r shows information of 3 posts

if ( $my_posts ) {
foreach( $my_posts as $post ) {
echo get_the_title( $post->ID);

}}
?>

print_r shows below text.

Array
(
    [s] => rabbit
    [posts_per_page] => -1
    [category_name] => atsugi
    [category__not_in] => Array
        (
            [0] => 3
            [1] => 137
            [2] => 571
        )

    [meta_query] => Array
        (
            [0] => Array
                (
                    [key] => 2a
                    [value] => Array
                        (
                            [0] => 2020-02-01
                            [1] => 2020-07-20
                        )

                    [compare] => BETWEEN
                    [type] => DATE
                )

        )

)
1
This appears to be the same as this question that you posted the day before. Please don’t re-post the same questions. If you have new information to add, you can edit the existing question using the ‘edit’ link under the question.FluffyKitten
I deleted question posted yesterday. Thank youcwhiro
The search function isn't necessary here, since it doesn't really help us. Also, don't print_r inside of the foreach loop. Try echo '<pre>' . print_r( $my_posts, TRUE ) . '</pre>'; immediately after $my_posts = get_posts( $args_normal ) and see what you get.disinfor
Thank you disinfor. I try it now.cwhiro
Disinfor, thank you for using your time for my question. Now I got right answer. I set 'suppress_filters' => false , and then filtering starts to work. I do appreciate your help these days. Thank you.cwhiro

1 Answers

0
votes

I set 'suppress_filters' => false, and then filtering started correctly. Regarding 'suppress_filters,' get_post function has default parameter "true", and it means filtering is not enable.