• Hi, community
    I am developing a new theme and I have a bug in the loop. Maybe somebody can see it better than me, after 2h of searching for the bug I am out of order right now.

    Them main problem is: My loop displays not only posts of the category 111, but also other posts. But not all other posts. and I cannot see any pattern, why and which posts are displayed besides those of cat 111. My code (I simplified it a little and kicked out some of the args, but the problem remains.) goes basically like this:

    <?php
    	$args = array(
    		'post_type'	=> 'post',
    		'category'      => 111,
    		'posts_per_page'=> -1,
    			);
    
    	$query = new WP_Query( $args );
    		if ( $query->have_posts() ) {
    			while ( $query->have_posts() ) {
    				$query->the_post();
    		?>
    
     	<div class="ratingliste"> 
    		 <h6>
     			<a href="<?php the_permalink(); ?>">
      				<?php the_title(); ?>
      			</a>
    </h6>
      	</div><!--.ratingliste-->
    	
    	<?php
    		}
    			}							         wp_reset_postdata();
    		?>

    But I tried all kind of loops, in the end I just googled them out and replaced parts of the loop with copy and paste. But the bug does not disappear.

    Has anybody an idea, why posts of other cats are also shown?

    THANKS!
    Raphael

    • This topic was modified 3 years, 8 months ago by rabox66.
    • This topic was modified 3 years, 8 months ago by rabox66.
    • This topic was modified 3 years, 8 months ago by rabox66.
    • This topic was modified 3 years, 8 months ago by rabox66.
    • This topic was modified 3 years, 8 months ago by rabox66.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Thread Starter rabox66

    (@rabox66)

    Hi Michael,
    thanks a lot. The problem was the wrong parameter “category”. This is a bit strange, cause it worked, but it did not work properly. If I replace “category” with “cat”, it works perfectly.

    But what interests me now is, why I did not receive an error message, if I use a parameter that does not exist. ??

    cat (int) – use category id.
    category_name (string) – use category slug.
    category__and (array) – use category id.
    category__in (array) – use category id.
    category__not_in (array) – use category id.

    Moderator bcworkz

    (@bcworkz)

    Because other devs might choose to add custom parameters. If WP errored out anything it didn’t understand such customization would be much more difficult. If WP doesn’t recognize a parameter, it simply ignores it.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Bug in custom loop’ is closed to new replies.