Skip Navigation

[Resolved] Can't retrieve posts with custom field value empty

This support ticket is created 6 years ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 15 replies, has 2 voices.

Last updated by Minesh 5 years, 11 months ago.

Assisted by: Minesh.

Author
Posts
#1165430

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - Please check what query generated based on the arguments you passed to Query:

SELECT   wp_posts.* FROM wp_posts  LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1  AND ( 
  wp_term_relationships.term_taxonomy_id IN (25,27,36) 
  AND 
  wp_posts.ID NOT IN (
				SELECT object_id
				FROM wp_term_relationships
				WHERE term_taxonomy_id IN (25,27)
			)
) AND wp_posts.post_type = 'carte-item' AND (wp_posts.post_status = 'publish' OR wp_posts.post_status = 'private') GROUP BY wp_posts.ID ORDER BY wp_posts.post_date DESC 

As you can see the argument is connected using "AND" clause and it says term_taxonomy_id IN (25,27,36) and term_taxonomy_id IN (25,27) - so I think this is the cause of the issue as when I change the argument to "OR":

For example - 'relation' =>'OR':

$args = array(
							'posts_per_page' => -1,
							'post_type' => $post_type,
							'tax_query' => array(
								'relation' =>'OR',
								array(
									'taxonomy' => $target_taxonomy,
									'field' => 'term_id',
									'operator' => 'IN',
									'terms' => $current_term->term_id,
								),
								array(
									'taxonomy' => $target_taxonomy,
									'field' => 'term_id',
									'operator' => 'NOT IN',
									'terms' => $children_term_ids,
								)
							)
						);
						
						
						$the_query = new WP_Query($args);

It outputs the content - it breaks output when you have "AND" in your argument, actually this is not Toolset issue as all but the custom query you wrote. For your any custom programming need, I suggest you to contact our certified partners:
=> https://toolset.com/contractors/