I am trying to build a "Popular Articles" area on all category pages, above the loop that displays posts. I've added a "Featured Post" checkbox on each post that allows the admin to mark certain posts as featured, and I've been able to display these posts at the top of each category page. BUT it currently displays ALL featured posts on all category pages, and I need the system to filter posts to show ONLY posts that are in the same category as the page on which they are displaying.
Here is what I'm using in my functions file that works well to display featured posts - any help adding in the category filtering is appreciated!
$args = array(
'posts_per_page' => 5,
'meta_key' => 'meta-checkbox',
'meta_value' => 'yes'
);
$featured = new WP_Query($args);
if ($featured->have_posts()): while($featured->have_posts()): $featured->the_post(); ?>
<h3><a href="<?php the_permalink(); ?>"> <?php the_title(); ?></a></h3>
<p class="details">By <a href="<?php the_author_posts() ?>"><?php the_author(); ?> </a> / On <?php echo get_the_date('F j, Y'); ?> / In <?php the_category(', '); ?></p>
<?php if (has_post_thumbnail()) : ?>
<figure> <a href="<?php the_permalink(); ?>"><?php the_post_thumbnail(); ?></a> </figure>
<p ><?php the_excerpt();?></p>
<?php
endif;
endwhile; else:
endif;
?>```