The Loop not working
-
[ Moderator note: moved to How-to and Troubleshooting. ]
I am writing two loops on same page,i want 5 posts with custom field(Url) and five without Url i am having lot of posts of both type and there author is not admin,i am attaching the code and output
[ Moderator note: code fixed. Please wrap code in the backtick character or use the code button. ]
<div class="1"><?php $old_query = new WP_Query( array ( 'post_type'=>post,'showposts'=>5,'author' =>-1 ) ); $i=1; ?> <?php if ( $old_query->have_posts() ):while ( $old_query->have_posts() ) :$old_query->the_post(); $Url= get_post_meta( $post->ID,'Url', TRUE ); if($Url==''){ echo $i."="; echo the_title(); echo ""; } $i++; endwhile; endif; wp_reset_query(); ?> </div><div class="2"> <?php $new_query = new WP_Query( array ( 'post_type'=>post,'showposts'=>5,'author' =>-1 ) ); $j=1; ?> <?php if ( $new_query->have_posts() ):while ( $new_query->have_posts() ) :$new_query->the_post(); $Url123= get_post_meta( $post->ID,'Url', TRUE ); if($Url123!=''){ echo $i."="; echo the_title(); echo ""; } $j++; endwhile; endif; wp_reset_query(); ?> </div> OUTPUT-: <div class="1">1=new title3=title4=new topiuc5=fghfghfghfgh </div> <div class="2"> 6=lorem Ipsum</div>
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
The topic ‘The Loop not working’ is closed to new replies.