Get latest 4 post on a custom post filtered by category
I’m trying to get the latest 4 posts filtered by category.
My post type are products.
I already tried wp_get_recent_posts, but it doesn’t have an attribute for category filter.
Then i tried with the WP_Query, but is not working too.
$args2 = array( 'post_type' => 'product', 'taxonomy' => 'product_cat', 'category' => '30278' ); $the_query = new WP_Query($args2); while ( $the_query->have_posts() ) : $the_query->the_post(); echo '<li>' . get_the_title() . '</li>'; endwhile;
It shows me always the same posts.
This is my recent post code:
$args = array('post_type' => 'product', 'numberposts' => 4, 'include' => get_cat_ID($atts['category']), ); wp_get_recent_posts($args, $atts['category']);
I tried to add in my args include, exclude, category and category name. without results.
I really don’t know how to solve this.
Thank you in advance.