Print out last 3 blogposts

You were not passing any limit to the query. $args = array( ‘posts_per_page’ => 3, ‘post_type’ => ‘post’, ‘post_status’ => ‘publish’, ‘ignore_sticky_posts’ => true ); $children = new WP_Query($args); if ($children->have_posts()) { while ($children->have_posts()) { $children->the_post(); // get_template_part( ‘header’, ‘blogheader’ ); // not on my server 🙂 } } wp_reset_postdata(); I made a couple of … Read more

get_posts always returning the same number of posts = 5

get_posts() has some defaults set, including numberposts equal to 5. Since it’s not considered to be a loop by itself those are independent and not affected by admin settings. So simply pass in arguments numberposts/posts_per_page (same thing) number for how many posts you want or -1 for all matching posts.

apply custom where to the default $wp_query

The posts_where filter should still fire. Just add it like this: function homepage_load_posts($query) { if ($query->is_home()) { add_filter( ‘posts_where’, ‘filter_where’ ); // And make the filter self-removing… // Create a new filtering function that will add our where clause to the query function filter_where( $where=”” ) { remove_filter( ‘posts_where’, ‘filter_where’ ); // posts 30 to … Read more

Get posts from multiple tax terms

I honestly don’t see how that works at all since get_the_term_list returns an HTML string. First, you need get_the_terms and wp_list_pluck. Second, you need a tax_query. That {tax} = {term} pattern is deprecated. $this_post = $post->ID; $args = array( ‘post_type’ => ‘dir_entry’, ‘posts_per_page’ => 10, ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘post__not_in’ => array($this_post), ); … Read more

WP_Query array key / value pairs?

Is there a list of the keys that can be used here. Is there a name for these key / value pairs. The “list” is in the Codex on the WP_Query page or you can just check the source. I don’t know what kind of “name” you are looking for. Other that “key/value” I’d call … Read more

Multiple Rows in a using wp_query

Get all of your posts in one query, then count the iterations of your loop. Pseudo-code follows. if ( $query->have_posts() ) { $i = 0; while ( $query->have_posts() ) { // If $i is 5 (5th post), end one row and start the next if (++$i == 5) { echo ‘</tr><tr>’; } // the rest … Read more

Event with multiple dates, display events chronologically

Here you go, explanations as comments // setup array to store things in while we loop $events_out = array(); // assume you already have your loop built the way you want while($loop->have_posts()) : $loop->the_post(); $instances = array(); // grab meta dates $instances[] = get_post_meta($post->ID, ‘dateA’, true); $instances[] = get_post_meta($post->ID, ‘dateB’, true); $instances[] = get_post_meta($post->ID, ‘dateC’, … Read more