I am trying to modify the [products] shortcode usage:
What I am looking was passing the author id from short code e.g [products author=2] to the query.
With the reference of: /
But the sample was a true/false parameter to trigger the $query_args change, seems it's not exactly my goal. And the function below is the only part I can put into use.
function htdat_woocommerce_shortcode_products_query( $query_args, $attributes ) {
$query_args = array(
//Receive the id//'author' => '1',
'post_status' => 'publish',
'post_type' => 'product',
'post_per_page' => 12,
);
return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'htdat_woocommerce_shortcode_products_query', 10, 2 );
If anyone could help, thank you.
I am trying to modify the [products] shortcode usage:
https://docs.woocommerce/document/woocommerce-shortcodes/#section-11
What I am looking was passing the author id from short code e.g [products author=2] to the query.
With the reference of: https://wordpress/support/topic/adding-a-special-product-attribute-to-the-products-shortcode/
But the sample was a true/false parameter to trigger the $query_args change, seems it's not exactly my goal. And the function below is the only part I can put into use.
function htdat_woocommerce_shortcode_products_query( $query_args, $attributes ) {
$query_args = array(
//Receive the id//'author' => '1',
'post_status' => 'publish',
'post_type' => 'product',
'post_per_page' => 12,
);
return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'htdat_woocommerce_shortcode_products_query', 10, 2 );
If anyone could help, thank you.
Share Improve this question asked Nov 24, 2020 at 13:07 Cwkin7Cwkin7 412 silver badges10 bronze badges1 Answer
Reset to default 1Try this:
function htdat_shortcode_atts_products( $out, $pairs, $atts, $shortcode ) {
if ( isset ( $atts['author'] ) ) $out['author'] = $atts['author'];
return $out;
}
add_filter('shortcode_atts_products', 'htdat_shortcode_atts_products', 10, 4);
function htdat_woocommerce_shortcode_products_query( $query_args, $attributes ) {
if ( isset( $attributes['author'] ) ) $query_args['author'] = $attributes['author'];
return $query_args;
}
add_filter( 'woocommerce_shortcode_products_query', 'htdat_woocommerce_shortcode_products_query', 10, 2 );