You can create a posts archive by just setting post_type=post
in your rewrite rule:
function custom_archive_rule() {
add_rewrite_rule(
'custom-archive/?',
'index.php?post_type=post',
'top'
);
}
add_action( 'init', 'custom_archive_rule' );
WordPress will identify this as is_home
, so you’ll have to target it in pre_get_posts
by the existence of your extra query variables.
function custom_arcive_tax( $query ) {
if ( $query->is_home()
&& $query->is_main_query()
&& isset( $_GET['cq'] ) ) {
$tax_query = array(
array(
'taxonomy' => 'category',
'terms' => $_GET['cq'],
)
);
$query->set( 'tax_query', $tax_query );
}
}
add_action( 'pre_get_posts', 'custom_arcive_tax' );