Run The Loop over array of post objects

I’m using this in one of my custom widgets: global $post; $posts = array( /* WP_Post, WP_Post, … */); while (list($i, $post) = each($posts)) : setup_postdata($post); // use the template tags below here if(has_post_thumbnail()): ?><div class=”featured_image_wrap”><?php the_post_thumbnail(); ?></div><?php endif; the_title(); endwhile; // don’t forget to restore the main queried object after the loop! wp_reset_postdata();

Users instead of posts: How to modify the main query?

Custom GET pagination parameter We can use a custom GET pagination parameter, e.g. upage or probably more unique as wpse-user-page, to use with your WP_User_Query. That way you avoid affecting e.g. the main post query. Generate pagination links with pageinate_links() We can use paginate_links() to generate the pagination: $args = array( ‘base’ => ‘%_%’, ‘format’ … Read more

Check if date of post is yesterday

As you discovered, one possible solution is something like: <?php $w_h = $w_d = 0; ?> <?php while (have_posts()) : the_post(); ?> <?php if ( date(‘Yz’) == get_the_time(‘Yz’) ) { if (!$w_d++) echo ‘Today<br />’; } elseif ( date(‘Yz’)-1 == get_the_time(‘Yz’) ) { if (!$w_h++) echo ‘Yesterday<br />’; } else { echo the_date(); }; ?>

How to Loop within a Loop (Display Children and then Grandchildren)

Try something like: <?php if ( have_posts() ) : ?> <?php while ( have_posts() ) : the_post(); ?> <div class=”parent-post”> <?php the_title(‘<h2>’, ‘</h2>’); ?> <?php $children = new WP_Query( array(‘post_type’ => ‘page’, ‘post_parent’ => get_the_ID() )); ?> <?php if ( $children->have_posts() ) : ?> <ul class=”post-children”> <?php while ( $children->have_posts() ) : $children->the_post(); ?> <li><?php … Read more