numberposts? showposts? posts_per_page?

In my opinion, deprecating numberposts would not make sense, as numberposts is used to query x amount of posts, whilst posts_per_page is used to denote how many posts per page are being shown during pagination. If you were to deprecate numberposts in favor of simply posts_per_page, then pagination would not exist. ie: “numberposts” => 50, … Read more

Should we trust the post globals?

There is a sad truth: you can never ever be sure that some code will not break your code, and there is nothing you can do to prevent that. Especially in WordPress, where everything is global. That said, yes, global $post is one of the most used global var, so using special care for it … Read more

How do I use WP_query with multiple post IDs?

Please reference the Codex entry for post/page parameters for WP_Query(). The ‘p’ parameter takes a single post ID, as an integer. To pass an array of posts, you need to use ‘post__in’: $myarray = array(144, 246); $args = array( ‘post_type’ => ‘ai1ec_event’, ‘post__in’ => $myarray ); // The Query $the_query = new WP_Query( $args );

Can i merge 2 new WP_Query($variable) ‘s?

You won’t do much good just merging the arguments, you need to merge the resulting posts array and the post_count count. This works for me: //setup your queries as you already do $query1 = new WP_Query($args_for_query1); $query2 = new WP_Query($args_for_query2); //create new empty query and populate it with the other two $wp_query = new WP_Query(); … Read more

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

WP_Query + random

Please try this: $args = array( ‘category_name’ => ‘cat1’, ‘posts_per_page’ => 5, ‘orderby’ => ‘rand’, ); $pc = new WP_Query( $args ); where ‘rand’ should give you a random order of your posts. For more info check out the Codex on WP_Query order parameters here.

Using pre_get_posts with WP_Query

The simplest way is to add the action right before the query and remove it immediately after. add_action(‘pre_get_posts’, ‘some_function_in_functionsphp’); $my_secondary_loop = new WP_Query(…); remove_action(‘pre_get_posts’, ‘some_function_in_functionsphp’); if( $my_secondary_loop->have_posts() ): while( $my_secondary_loop->have_posts() ): $my_secondary_loop->the_post(); //The secondary loop endwhile; endif; wp_reset_postdata(); EDIT Another technique you can use is to set your own query var and check for that … Read more

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