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() ) :
    echo '<li>' . get_the_title() . '</li>';

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.

, Kryuko 4 years 2020-07-20T13:11:25-05:00 0 Answers 54 views 0

Leave an answer