WP_Query infinite Loop

You need $form_enquiries->the_post() to “push” the loop onto the next post – otherwise yes, you get an infinite loop! while ( $form_enquiries->have_posts() ) { $form_enquiries->the_post(); // rest of your loop }

Why post__not_in is ignored?

As per the Codex entry: “post__not_in (array) – use post ids. Specify post NOT to retrieve. If this is used in the same query as post__in, it will be ignored.“ Try to make an array of the post id’s you do want to display, OR an array of the post id’s you want to exclude … Read more

get data match with extra field value using wp_query for custom post

Change your WP Query arguments like this: $args = array( ‘post_type’ => ‘assignment’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘batch’, ‘meta_value’ => ‘2017’, ); For multiple post meta you can use meta_query like this $args = array( ‘post_type’ => ‘assignment’, ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘color’, ‘value’ => ‘blue’, ), array( ‘key’ … Read more

How to count posts with specific arguments

The easiest way to optimize this query would be to add ‘fields’ => ‘ids’ to the arguments. This way only ids of posts will be retrieved from DB (and usually that’s a big change). $args = [ ‘numberposts’ => -1, ‘post_type’ => ‘jobs’, ‘s’ => ‘developer’, ‘tax_query’ => [‘taxonomy’ => ‘IT’, ‘field’ => ‘slug’], ‘fields’ … Read more

Is there something wrong w/ this code?

It should be this: WP_Query Order By Parameters <?php $rp = new WP_Query(array( ‘post_type’ => array( ‘post’,’videos’,’projects’ ), ‘orderby’ => ‘date’, ‘order’ => ‘DESC’, ‘posts_per_page’ => 4 )); while ($rp->have_posts()) : $rp->the_post(); ?>

wp_query with parameters

Assuming you have variables to hold your custom values for each: $category $tag $author $search Then just create an arguments array, and add keys to it conditionally: $custom_query_args = array( // Set any default args here // NOTE: This is where you’d add // things like pagination (posts_per_page), // order/sort parameters, and the like ‘posts_per_page’ … Read more