Resetting post data to previous loop in nested loops

I’m going to answer this myself, but it was the very clever @simonwheatley of Code for the People that solved this one for me. Instead of using wp_reset_postdata() or wp_reset_query(), you can use the following: $publication->reset_postdata(); Where $publication is your query object. The working code now looks like: $publication = new WP_Query( array( ‘connected_type’ => … Read more

Why should I put if(have_posts()), is while(have_posts()) not enough?

The WordPress template loader will include the appropriate contextual template file in many circumstances, even if the query for that context returns no posts. For example: The Main Blog Posts Index Category Archive Index (Category exists, but has no posts) Tag Archive Index (Tag exists, but has no posts) Author Archive Index (Author exists, but … Read more

Get post content from outside the loop

You can use get_page() to return the $post object of a static page: $page_id = 302; $page_object = get_page( $page_id ); echo $page_object->post_content; Edit Similarly, you can use get_post() to return the $post object of a post: $post_id = 302; $post_object = get_post( $post_id ); echo $post_object->post_content;

if ( is_home() && ! is_front_page() )

This will display the title of the page when a static page is set to show posts. E.g. I show posts on my homepage… It’ll do nothing. If I, say, show posts on page titled News… It’ll show News in H1. This is used so that the title of the page is shown, whenever posts … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)