Finally, I could solve my problem. I show my final code for somebody else who stacks by same problem.
This is URL I refered.
https://wordpress.stackexchange.com/questions/142603/merged-two-wp-queries-posts-per-page-and-pagination-not-working?newreg=70dbebb78f9946658d28d580fb55c8c0
Final Code
<?php
$args_a = get_posts(
array(
'fields' => 'ids',
'posts_per_page' => -1,
'paged' => $paged,
'category_name' => 'shinmatsudo',
'category__in' => array( 227 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '1b',
'compare' => 'NOT EXISTS'
),
array(
'key' => '1d',
'compare' => 'NOT EXISTS'
),
//etc
),
));?>
<?php
$args_b = get_posts(
array(
'fields' => 'ids',
'category_name' => 'matsudo',
'posts_per_page' => -1,
'paged' => $paged,
'category__in' => array( 329 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '1b',
'compare' => 'NOT EXISTS'
),
array(
'key' => '1d',
'compare' => 'NOT EXISTS'
),
//etc
),
)); ?>
<?php $post_ids = array_merge( $args_a, $args_b); ?>
<?php
$the_query = new WP_Query(
array(
'post_type' => 'any',
'post__in' => $post_ids,
'paged' => $paged,
'orderby' => 'date',
'order' => 'DESC',
'posts_per_page' => 9,
)
);
?>
//I set my pagination for page here. I think any place is ok.
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title() ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
These are some of codes I failed these days. Somebody plese give me tips.
Failed Code #1
This code shows only 1 title of the latest post.
On page
<?php
$args_a = get_posts( array(
'suppress_filters' => false,
'category_name' => 'shinmatsudo',
'category__in' => array( 227 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '1b',
'compare' => 'NOT EXISTS'
),
//etc..
),
));
$args_b = get_posts( array(
'suppress_filters' => false,
'category_name' => 'matsudo',
'category__in' => array( 329 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'and',
array(
'key'=> '2a',
'value' => array('2020-02-01' , '2020-06-01'),
'compare' => 'BETWEEN',
'type' => 'DATE',
),
//etc..
),
));
// Use your original args, but add a parameter.
$args = array_merge($args_a, $args_b, [ 'custom_query' => TRUE ] );
?>
<?php $the_query = new WP_Query( $args );?>
<?php include("pagination-page.php")?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title() ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
On function.php
add_filter( 'pre_get_posts', static function( $query ) {
// Check to see if 'custom_query' is set to TRUE.
if ( ! is_admin() && $query->custom_query ) {
$query->set( 'paged', TRUE );
$query->set( 'posts_per_page', 4 );
$query->set( 'orderby', 'date' );
}
});
Failed Code #2
I tried without get_posts
like this. This code shows reslut of $args_b only.
<?php
$args_a = array(
'posts_per_page' => 10,
'category_name' => 'shinmatsudo',
'category__in' => array( 227 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '1b',
'compare' => 'NOT EXISTS'
),
//etc..
),
);
$args_b = array(
'posts_per_page' => 10,
'category_name' => 'matsudo',
'category__in' => array( 329 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'and',
array(
'key'=> '2a',
'value' => array('2020-02-01' , '2020-06-01'),
'compare' => 'BETWEEN',
'type' => 'DATE',
),
//etc..
),
);
$args = array_merge($args_a, $args_b );
?>
<?php $the_query = new WP_Query( $args );?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title() ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
Faild Code #3
I use custom query with pre_get_posts.
Result is same like Code #2. $args_b only shown as result.
On Page
<?php
$args_a = array(
'posts_per_page' => 10,
'category_name' => 'shinmatsudo',
'category__in' => array( 227 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '1b',
'compare' => 'NOT EXISTS'
),
//etc..
),
);
$args_b = array(
'posts_per_page' => 10,
'category_name' => 'matsudo',
'category__in' => array( 329 ),
'category__not_in' => array( 3 ),
'meta_query' => array(
'relation' => 'and',
array(
'key'=> '2a',
'value' => array('2020-02-01' , '2020-06-01'),
'compare' => 'BETWEEN',
'type' => 'DATE',
),
//etc..
),
);
// Use your original args, but add a parameter.
$args = array_merge($args_a, $args_b, [ 'custom_query' => TRUE ] );
?>
<?php $the_query = new WP_Query( $args );?>
<?php if ( $the_query->have_posts() ) : while ( $the_query->have_posts() ) : $the_query->the_post(); ?>
<?php the_title() ?>
<?php endwhile; ?>
<?php endif; ?>
<?php wp_reset_query(); ?>
On Function.php
<?php
add_filter( 'pre_get_posts', static function( $query ) {
// Check to see if 'custom_query' is set to TRUE.
if ( ! is_admin() && $query->custom_query ) {
$query->set( 'paged', TRUE );
$query->set( 'posts_per_page', 4 );
$query->set( 'orderby', 'date' );
}
});
?>