• Resolved jrcollins

    (@jrcollins)


    My theme is using a custom loop to generate posts. Can anyone tell me how to modify it so as to show posts from one category only?

    <?php if ( have_posts() ) : ?>
    
    				<?php $the_query = new WP_Query( array('posts_per_page'=>$mantra_options['mantra_frontpostscount']) ); ?>
    				<?php while ( $the_query->have_posts() ) : $the_query->the_post(); ?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • You should be able to add a new option to the array being passed to WP_Query to solve your problem…

    Query by name… (this is actually the SLUG, not the name)
    <?php $the_query = new WP_Query( array(‘category_name’=>’special_cat’,’posts_per_page’=>$mantra_options[‘mantra_frontpostscount’]) ); ?>

    Or by ID…
    <?php $the_query = new WP_Query( array(‘cat’=>1,’posts_per_page’=>$mantra_options[‘mantra_frontpostscount’]) ); ?>

    Check out the Parameters section of the WP_Query page in the codex for more things you can use for filtering ?? Good luck! https://codex.www.ads-software.com/Class_Reference/WP_Query#Parameters

    Thread Starter jrcollins

    (@jrcollins)

    Hey, thanks for your help. That was a nice and easy solution.

    Anytime!

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘show posts from category’ is closed to new replies.