why the same code got different results when using query_posts in functions.php and index.php

In your first code example, you hook into the pre_get_posts action, which fires during the main query. But instead of manipulating that query, you trigger another one using query_posts(), which fires the hook again, and you end up with an infinite loop. With the second code example, you’re just overriding the main query after it’s … Read more

Automatically create a default set of posts for each new registered user

A combination of user_register and wp_insert_post should work fine: add_action(‘user_register’, ‘create_postset’); function create_postset($user_id) { // userinfo $user_info = get_userdata($user_id); // Create post objects $post_1 = array( ‘post_title’ => ‘1st post created for ‘ . $user_info->user_login, ‘post_content’ => ‘Lorem Ipsum’, ‘post_status’ => ‘publish’, ‘post_author’ => $user_id ); $post_2 = array( ‘post_title’ => ‘2nd post created for … Read more

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

How to Display Posts From Category Within a Custom Taxonomy?

@Krzysiek answer above didn’t work because have_posts is a method not a property. It should be have_posts() not have_posts. Here’s the corrected code: $my_query = new WP_Query( array( ‘post_type’=>’news’, ‘posts_per_page’=>4, ‘tax_query’=>array( array( ‘taxonomy’=>’instituteName’, ‘field’=>’slug’, ‘terms’=>’businessschool’ // change to real slug ) ) ) ); while ( $my_query->have_posts() ) { $my_query->the_post(); // display post }

How to make different custom post layouts?

To rephrase, I believe what you’re asking is how can you have a different style or template for your custom post types when they are displaying as a list? It looks like the Custom Post Templates plugin you’re using only allows you to switch templates for the single view of a post, not the listing … Read more