Reputation: 566
In a woocommerce installation with Divi theme installed I am using products shortcode: [products limit="-1" columns="3" per_page="12" paginate="true"]
. In functions.php
I am trying to filter the products displaying by using woocommerce_product_query
but it is not working. I am still getting all the products
function my_pre_get_posts_query2( $query ) {
$query->set( 'post__in', [245609, 245610]);
}
add_action( 'woocommerce_product_query', 'my_pre_get_posts_query2', 9999, 1 );
Upvotes: 0
Views: 678
Reputation: 227
You can do that in two ways:
1. By adding attribute "ids" in the product listing shortcode
[products limit="-1" columns="3" per_page="12" paginate="true" ids="245609, 245610"]
2. By filter hook for product shortcode to add the attribute ids
Something like below,
add_filter( 'woocommerce_shortcode_products_query', 'woocommerce_shortcode_products_by_specific_ids' );
function woocommerce_shortcode_products_by_specific_ids( $args ) {
$args['ids'] = array(245609, 245610);
// if above line not working then try with below line
// $args['ids'] = "245609, 245610";
return $args;
}
Upvotes: 1