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 }
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 }
Remove this part from your posts_where filter: if (is_search() && get_search_query()) Note that is_search() is a check on the main query. If you want to target the main search query, there’s the posts_search filter available. Important: Watch out for possible SQL injections, as you are taking user input into the SQL query. I think the … Read more
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
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
The answer to my general question has a very specific answer, and I found the answer by running across this answer to more or less the same problem. Basically GoDaddy hosting does something special to utm_-type query strings. Tech support could provide no detail. In case anyone else runs across this, it looks like something … Read more
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
As documented, you can set the compare property of the meta query to NOT EXISTS: $args[‘meta_query’] = array( array( ‘key’ => ‘instrument’, ‘compare’ => ‘NOT EXISTS’, ), );
You should always use get_post_meta. Your attempt to micro-optimise using a raw SQL query will reduce not improve performance. When you fetch a post, WordPress bulk fetches its meta for performance reasons, so if you used get_post_meta it would already have the answer in memory. If your site has an object cache then it would … Read more
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(); ?>
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