0

I want to modify the Recent Products section Storefront theme to be able to include juste a specific category. i tried that :

add_filter( 'storefront_recent_products_args', 'my_custom_storefront_category_args' );
function my_custom_storefront_category_args( $args ){
   $args = array(
    'limit' => 8,
    'columns' => 4,
    'category__in' => array ('35') 
    );
  return $args;
 }

but no success

4
  • I don't know Storefront, but I'd guess you want to modify the $args array passed in not completely overwrite it. What are those args used for? I'd guess not WP_Query since that doesn't have a columns value.
    – Rup
    Nov 21, 2021 at 23:11
  • Yes I saw that. I think WP_Query () is not used. instead the [products] shortcode. I just want to add a Category coding. kept the same result, but for a product list of a category.
    – Younes.D
    Nov 22, 2021 at 12:49
  • I found it , the question is resolved : add_filter( 'storefront_recent_products_args', 'my_custom_storefront_category_args' ); function my_custom_storefront_category_args( $args ){ $args = array( 'limit' => 6, 'columns' => 3, 'orderby' => 'date', 'order' => 'desc', 'category' => 'your-cat-slug', 'cat_operator' => 'AND' ); return $args; }
    – Younes.D
    Nov 22, 2021 at 13:09
  • Yes please mark it as solved
    – Younes.D
    Nov 22, 2021 at 15:15

1 Answer 1

1

I found it , the question is resolved : Solution :

add_filter( 'storefront_recent_products_args','my_custom_storefront_category_args' );
function my_custom_storefront_category_args( $args ){ 
    $args = array( 
    'limit' => 6, 
    'columns' => 3, 
    'orderby' => 'date', 
    'order' => 'desc', 
    'category' => 'your-cat-slug', 
    'cat_operator' => 'AND' 
    );

    return $args; 
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.