WP_Query with Metavalue

Question

I have developed this function but returns 0 results. I think there is a problem with the way I am passing the meta_value arguments. Any help?

add_shortcode( 'sc_count_brands', 'sc_count_brands_code' );
function sc_count_brands_code($atts) {
   $values = shortcode_atts( array('category'  => 'Horology',), $atts );
   $query = new WP_Query( array( 'post_type' => 'brands',  'post_status' => 'publish', 'meta_key' => 'br_category', 'meta_value' => esc_attr($values['category']) ) );
   $countn = $query->found_posts;
   $buffer = '<span class="magby">Featuring </span><span class="axiac">' . $countn . '</span><span class="magby"> brands</span>';
   wp_reset_postdata();
   return $buffer;
}
0
Joanna Mikalai 3 years 2019-10-22T08:46:13-05:00 0 Answers 60 views 0

Leave an answer

Browse
Browse