Array ids post to function have_post

If I understand it properly, You can use the post__in parameter to query for specific posts where the post ID is in that parameter: $ids = [ 1, 2, 3, 4, 5 ]; $query = new WP_Query( array( ‘post__in’ => $ids, // … other args, if any. ) ); // Then loop through the posts. … Read more

Change date format

You will need to use strtotime() with Date() to make your own date format If you already know the meta key that you need you can do the following $post_meta_data = get_post_meta(get_the_ID(), ‘endDate’, true); See get_post_meta for more information about the function. Now that we have the value and going your format all you need … Read more

Include multiple page ids in loop

page is not an accepted parameter for WP_query , you can use page_id but that doesn’t accept an array , only one specific ID, so just use post__in like this: <?php $args = array( ‘post__in’ => array(139, 54) ); $loopy = new WP_Query($args); while ($loopy->have_posts()) : $loopy->the_post(); ?> <div class=”item”><?php the_title(); echo ‘<br ?>’; echo … Read more

Stepping through a foreach loop – adding +1 to the end of it so next time it loops it starts on item 2

Use the offset argument, and only get 1 result: global $my_page_offset; if(!isset($my_page_offset)) $my_page_offset = 0; $pages = get_pages(array( ‘child_of’ => $post->ID, ‘sort_column’ => ‘menu_order’, ‘offset’ => $my_page_offset, ‘number’ => 1, )); $my_page_offset++; … I’m assuming here that you don’t have much control over these loops, because you’re doing them multiple times. This is why the … Read more

Add class to last 3 posts in loop

WP_Query seems to set two variables, $posts and $post_count when running(according to the source over at http://core.trac.wordpress.org/browser/tags/3.2.1/wp-includes/query.php ). You can access these two and work something out to figure out if you’re in the last three posts. var_dump those two to see if there’s a count, add in your own counter and you should be … Read more

Group posts by date with a list

I usually perform a simple check to see if that day has changed. <?php $day_check = ”; while (have_posts()) : the_post(); $day = get_the_date(‘j’); if ($day != $day_check) { if ($day_check != ”) { echo ‘</ul>’; // close the list here } echo get_the_date() . ‘<ul>’; } ?> <li><a href=”#”><?php the_time(); ?><?php the_title(); ?></a></li> <?php … Read more

Enabling users to control custom loop’s query

User meta is the way to go friend! When you register the user via whatever you’re using, save this preference as user meta for this user. Then when you render the template, get the current user id, and get this user meta before the loop and use it in the loop.