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
)
)
)
print_r
inside of theforeach
loop. Tryecho '<pre>' . print_r( $my_posts, TRUE ) . '</pre>';
immediately after$my_posts = get_posts( $args_normal )
and see what you get. – disinfor