Only show current category post

Question

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?

0
, , , , WeebleWobb 6 years 2016-11-07T19:45:59-05:00 0 Answers 96 views 0

Leave an answer

Browse
Browse