Create a WP_Query with Category and Sticky Posts
-
In the current code below, the WP_Query, in the theme’s index.php, is supposed to display the posts from one category and put the sticky posts at the top. The results are the posts are sorted by date and the sticky posts aren’t at the top. How do I get this criteria to work in the code?
I also tried with two WP_Query loops, one for the sticky posts and one for the other posts but that was very confusing and was giving me a headache.
Here is the current code:
<?php $paged = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; $args_posts = new WP_Query(array( 'post_type' => 'post', 'post_status' => 'publish', 'cat' => '1', 'posts_per_page' => 5, 'paged' => $paged )); if ($args_posts->have_posts()): while ($args_posts->have_posts()) : $args_posts->the_post(); $titleLink = get_post_meta($post->ID, '_mcf_title_link', true); ?> <div id="post-<?php $this_page_id = get_the_ID(); echo $this_page_id; ?>" class="post"> <div class="entry"> <?php if (!empty($titleLink)) : ?> <h3> <a href="<?php echo $titleLink; ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </h3> <?php $path = $_SERVER['SCRIPT_NAME']; elseif ($path == "/ecotourism/") : ?> <div id="ecotitle"> <h1> <a href="<?php echo $titleLink; ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a> </h1> </div> <?php else : ?> <h3> <a href="<?php the_permalink() ?>" title="<?php the_title(); ?>"> <?php the_title(); ?></a> </h3> <?php endif; the_content(); edit_post_link('edit', '<p class="postmetadata">', '</p>'); ?> </div> <div style="clear:both;"></div> </div> <?php endwhile; endif; ?>
Viewing 9 replies - 1 through 9 (of 9 total)
Viewing 9 replies - 1 through 9 (of 9 total)
- The topic ‘Create a WP_Query with Category and Sticky Posts’ is closed to new replies.