I'm writing plugin for syncing prices of WooCommerce products with external source. So I want to get products with EAN (have meta data
_wpm_gtin_code). Whaterver I pass to
get_posts($args) I get empty data. I'm using WordPress 5.3.2.
I dived into WP source to track why. When I print generated SQL
wp-includes/class-wp-query.php:2890 I see it contains "where condition"
AND (0 = 1) which obviously cannot succeed. This piece of code is inserted by Taxonomies called on
wp-includes/class-wp-query.php:2101-2109, explicitly by
$clauses = $this->tax_query->get_sql( $wpdb->posts, 'ID' ); $where .= $clauses['where'];.
I didn't dig deeper into
$this->tax_query->get_sql(...). What I know is that I don't pass any taxonomy arguments to
get_posts($args), so I don't expect it to influence the query.
How shall I call
get_posts($args) to get all posts just of some type and status?
$meta_query = array( 'relation' => 'OR', array( 'key' => '_wpm_gtin_code', 'compare' => 'EXISTS' ), array( 'key' => '_product_code', 'compare' => 'EXISTS' ) ); $args = array( 'meta_query' => $meta_query, 'post_type' => 'product', 'post_status' => 'publish', 'posts_per_page' => -1, ); error_log(print_r($args, true)); // print args $posts = get_posts( $args ); error_log(print_r($posts, true)); // print posts - empty!!!