Duplicates When using Nested WP_Query

Never mind, I got it. For anyone who may run into a similar issue. See below. Main Loop: if ( $the_query->have_posts() ) { while ( $the_query->have_posts() ) { unset($do_not_duplicate); $the_query->the_post(); } } Secondary Loop: if ( $projects_query->have_posts() ) { while ( $projects_query->have_posts() ) { $do_not_duplicate[] = get_the_ID(); if( in_array( get_the_ID(), $do_not_duplicate) ) continue; } }

Query with two posttypes and two different meta_keys

Have you tried this? ‘meta_query’ => array( ‘relation’ => ‘AND’, array( ‘relation’ => ‘OR’, array( ‘key’ => ‘start_date’, /// or ‘end_date’ for cpt ‘group_of_events?? ‘compare’ => ‘BETWEEN’, ‘type’ => ‘DATE’, ‘value’ => array($filter_start_date, $filter_end_date), ), array( ‘key’ => ‘end_date’, /// or ‘end_date’ for cpt ‘group_of_events?? ‘compare’ => ‘BETWEEN’, ‘type’ => ‘DATE’, ‘value’ => array($filter_start_date, $filter_end_date), … Read more

Select posts wich has no relationship in custom taxonomy

I have found an answer by myself, for those landing here by google: $taxq = array( array( ‘taxonomy’ => ‘story_lng’, ‘field’ => ‘id’, ‘operator’ => ‘NOT EXISTS’, ) ); That results in AND (NOT EXISTS( SELECT 1 FROM wp_term_relationships INNER JOIN wp_term_taxonomy ON wp_term_taxonomy.term_taxonomy_id = wp_term_relationships.term_taxonomy_id WHERE wp_term_taxonomy.taxonomy = ‘story_lng’ AND wp_term_relationships.object_id = wp_posts.ID)) AND … Read more

How to order by datediff in WP loop?

You can handle this by define DATEDIFF() in SELECT For example: SELECT RECID, DATEDIFF(t1.qr_enddate, NOW()) AS diffORD FROM `mytablw` t1 ORDER BY diffORD ASC; This should work but in your case I strongly recommend to use wordpress default Filter API posts orderby. This filter is applied before a post-retrieving SQL statement is executed. Use it … Read more

Pagination returns 404 after page 20

What you are experiencing is quite normal and expected. This is one of the big reasons I always hammer on this point, never use custom queries to replace the main query on the home page or any type of archive page. They solve one issue but creates plenty other new ones Lets look at what … Read more