I've ran into trouble, i do not understand how to make my custom query respect the current category i'm browsing.
Lets say i'm in category "test1" and i have this custom query loop:
$paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1;
$query_args = array(
'post_type' => 'post',
'post_status' => array('private', 'publish'),
'posts_per_page' => 20,
'paged' => $paged,
);
$the_query = new WP_Query( $query_args );
if ( $the_query->have_posts() ) :
while ( $the_query->have_posts() ) : $the_query->the_post();
This will take all posts that are private/publish and show them on all pages, even if i am browsing a category..... How do i add some a custom query that respect the current category?
If i add cat'=> '1',
and specify a category, it obviously only grabs the category i specify.
I've desperately tried to use in house functions such as:
$category = get_queried_object();
echo $category->term_id;
inside the 'cat'=> '',
statement but that obviously doesn't work. I've also tried to use php if / else statments inside the array in hopes of being able to generate the category id based on where i am browsing on the site such as:
if (is_category(1)) {
'cat' => '1', } else { 'cat' => '12', }
How do i go about solving this?
pre_get_posts
to modify the main query without editing the template.