WordPress.org

Support

Support » How-To and Troubleshooting » query_posts category_name and showposts problem

query_posts category_name and showposts problem

  • I’m having a bit of trouble getting a query_posts to work.

    For some reason, the showposts parameter isn’t working, when I specify the category. For example, if I did just a regular

    <?php
    
    //The Query
    query_posts('showposts=9');
    
    if (have_posts()) {
    	while (have_posts()) {
             ...
    	}
    }
    
    wp_reset_query();
    
    ?>

    It works fine, and shows nine posts, but if I do

    <?php
    
    //The Query
    query_posts('category_name=The Category Name&showposts=9');
    
    if (have_posts()) {
    	while (have_posts()) {
    		the_post();
    		cfct_template_file('content', 'third');
    	}
    }
    
    wp_reset_query();
    
    ?>

    All it does is display that category. I’ve also tried using ‘cat=111’, and ‘posts_per_page=9’, but they both just show the entire category. When I exclude categories it works fine though.

Viewing 8 replies - 1 through 8 (of 8 total)
  • What is it you want query posts to return?

    If you specify showposts=9 and category=111, then you will only see UP TO 9 posts for that category 111. If there are only 3 posts in that category, that’s all you would see.

    What’s happening for me is that it returns all of the posts in my category, not recognizing showposts. So if there were 20 posts in that category, it would show all of them.

    Try this:

    <?php
    $args=array(
      'category__in' => array(111),
      'showposts'=>9,
      );
    $first_loop = new WP_Query($args);
    if ($first_loop->have_posts()) : while ($first_loop->have_posts()) : $first_loop->the_post();
    ?>
    <p><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></p>
    <?php endwhile;
    ?>
    <?php else : ?>
    <h2>You forgot to create any posts !</h2>
    <?php endif; ?>

    I’m using wp 2.8.4. I have exactly same problem.
    Either query_posts() or WP_Query() shows all posts in a category ignoring shosposts.
    Is there any problem in wp functions or should I need to check my theme?

    try adding $query_string. and & in query posts like this

    <?php query_posts($query_string.’&category_name=The Category Name&showposts=5′); ?>

    Same problem here with 2.8.4…Strange. Had to use an $i counter to limit posts.

    I’m having the same issue as well, and I’m also using the Carrington framework (like timsainb). In my case, it’s Carrington JAM 1.3 and WP 2.8.4. This is the second site that I’ve done with Carrington that’s had me pulling my hair out over this particular issue.

    I was having the exact same problem using WP 2.8.5 and Carrington JAM 1.3. I took my code out of the loop in Carrington and dropped it into the index.php in the default theme and it worked just fine. So, this sounds like a Carrington issue.

    Here was the code I used (works in default theme, not in Carrington):

    <ul>
    	<?php
    		$args=array(
    			'category_name' => 'features',
    			'posts_per_page' => 15
    		);
        	$editorials = new WP_Query($args);
    		if($editorials->have_posts()) : while($editorials->have_posts()) : $editorials->the_post();
    	?>
    	<li>
    		<a href="<?php the_permalink(); ?>" title="Read the article &quot;<?php the_title(); ?>&quot;"><?php the_title(); ?></a>
    	</li>
    	<?php endwhile; endif; ?>
    </ul>

    I have started a discussion on this topic over in the Carrington forums: http://groups.google.com/group/carrington-framework/browse_thread/thread/b2da3379c608a5b

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘query_posts category_name and showposts problem’ is closed to new replies.
Skip to toolbar