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

deneme bonusu veren sitelerbahis casinomakrobetceltabetpinbahispolobetpolobet girişpinbahis girişmakrobet girişpulibet girişmobilbahis girişkolaybet giriş