I have created a custom loop using WP_Query
to show posts associated to a custom post type I created.
<?php
$the_query = new WP_Query( array (
'post_type' => 'scp_content'
));
?>
<?php
if( $the_query->have_posts() ) : while( $the_query->have_posts() ) : $the_query->the_post(); ?>
<section id="post-<?php the_id(); ?>" class="main-content">
<h2><?php the_field( 'section_heading' ); ?></h2>
<div class="container-fluid col-lg-9">
<p><?php the_field( 'section_content' ); ?></p>
</div>
</section>
<?php endwhile; endif; wp_reset_postdata(); ?>
Each post has one specific category assigned and all categorized posts can be viewed when the said category is clicked via a category menu that I created.
The issue: Regardless of which category I click, I am shown all posts. I have tried implementing: get_category();
, get_query_var();
, get_the_category();
and is_category();
within my loop to try and specify posts shown via current category selected but to no success.
Assuming I am using these function incorrectly, how can I show the current category posts when a user clicks on the specific category in the menu?
has_archive
to true, you don't need the custom query you have above.