我正在尝试修改短代码用法:
https://docs.woocommerce.com/document/woocommerce-shortcodes/#section-11
我所看到的是将作者id从简短的代码(例如)传递给查询。
参考:https://wordpress.org/support/topic/adding-a-special-product-attribute-to-the-products-shortcode/
但是这个示例是一个触发$query_args更改的真/假参数,似乎这并不是我的目标。下面的功能是我唯一可以使用的部分。
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 );如果有人能帮忙的话,谢谢。
发布于 2020-11-24 13:28:48
试试这个:
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 );https://wordpress.stackexchange.com/questions/378738
复制相似问题