Issue with sticky posts and WP_Query on front-end
-
Hey guys! New to PHP here. This is the first theme I ever wrote just about entirely myself and pretty happy with it. However, today I published a new post and noticed something weird, maybe ya’ll can give me a tip on how to improve on my code?
Go to Bullworhy.com and notice in the “issuer alerts” div on the left-hand side of the main content section I’ve got a line at the top that reads “Genius Brands International (GNUS) Leveraging Digital Footprint To Drive Brand Recognition”…this is a post tagged with the category “Issuer Alerts” and queried using the code below.
The post below that is sticky, so it’s got it’s own little section. However, the GNUS post is supposed to show up under the query titled “More Issuer Alerts” just below the title and above the
“Bullworthy, LLC Initiates Coverage on Oriens Travel & Hotel Management Corp (Pinksheets: OTHM) With Detailed Equity Research Report and $0.10 Price Target”.Here’s the code. Any idea why the GNUS post is showing ABOVE the sticky post and not in the “More Issuer Alerts” section where it should be?? All else being equal of course (i.e. the new GNUS post is tagged correctly, it’s not sticky, etc.)
<div id="issuer-alerts"> <?php $my_query = new WP_Query('category_name=issuer-alerts&posts_per_page=10'); while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?> <div id="post-<?php the_ID(); ?>" <?php post_class(); ?>> <?php if (is_sticky () ) { ?> <h1 class="post-title"><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h1> <span class="released">Released on <?php the_date( 'l, F t Y' );?> at <?php the_time( 'g:i a' ); ?></span> <div class="post-entry"> <div class="thumb"> <?php if ( has_post_thumbnail()) : ?> <a href="<?php the_permalink(); ?>" ><?php the_post_thumbnail( array('class' => 'alignleft') ); ?></a> <?php endif; ?> </div><!-- thumb --> <div class="excerpt"><?php the_excerpt(); ?> <?php $key = 'field_name'; $themeta = get_post_meta($post->ID, 'report_link', true); if($themeta != '') { echo '<div class="read-more" style="margin-bottom: 5px;"><a href="' . get_post_meta($post->ID, 'report_link', true) . '" target="_blank">Access This Report Now</a></div>';} ?> <div class="read-more"><a href="/issuer-alerts">View All Issuer Alerts</a></div> </div><!-- excerpt --> </div><!-- end of post-entry --> <div class="clear"></div> <h3>More Issuer Alerts:</h3> <?php } else { ?> <li><a href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></li> <?php } ?> </div><!-- post-ID --> <?php endwhile; ?> </div><!-- issuer-alerts -->
- The topic ‘Issue with sticky posts and WP_Query on front-end’ is closed to new replies.