user91325
user91325

Reputation: 21

How to create wordpress loop by category

I am trying to create a wordpress loop for only a specific category of posts. For some reason, the loop I am using for category does not seem to work. It simply displays all posts. As an example, I want to loop the category of "apples"

This is the code -

 <?php get_posts('cat=apple'); ?>
  <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    <?php the_content(); ?>

(Bunch of html/css)

 <?php endwhile; endif; ?>

any ideas why it is not working?

Upvotes: 1

Views: 45

Answers (1)

Rick
Rick

Reputation: 78

You are calling the category wrong, see https://codex.wordpress.org/Template_Tags/get_posts on how to set your arguments.

Upvotes: 1

Related Questions