$args = array(
'p' => $product_id,
'post_type' => array( 'product' ),
'post_status' => array( 'publish' ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_ywar_product_id',
'value' => $product_id,
'compare' => '=',
'type' => 'NUMERIC',
),
array(
'key' => 'recommend_it',
'value' => 'yes',
'compare' => '=',
'type' => 'CHAR',
),
),
);
// The Query
$query = new WP_Query( $args );
echo $query->found_posts;
The result is shown 0 only.
$args = array(
'p' => $product_id,
'post_type' => array( 'product' ),
'post_status' => array( 'publish' ),
'meta_query' => array(
'relation' => 'AND',
array(
'key' => '_ywar_product_id',
'value' => $product_id,
'compare' => '=',
'type' => 'NUMERIC',
),
array(
'key' => 'recommend_it',
'value' => 'yes',
'compare' => '=',
'type' => 'CHAR',
),
),
);
// The Query
$query = new WP_Query( $args );
echo $query->found_posts;
The result is shown 0 only.
You use the "p"-argument, which looks for the wordpress Post-ID. I guess you want to search the products, that have $product_id in the meta, not for the exact post with the ID $product_id. Just remove the "p" argument from your wp_query arguments.