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 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

Loop don’t work within single.php page

To give you a more thorough answer I would have to see some actual code, but I think the gist of the answer is in the file you are trying to use. “single.php” is the template file used to display the content of a single post, as the name implies. It isn’t meant for displaying … Read more