【问题标题】:Woocommerce - Query filter author productWoocommerce - 查询过滤器作者产品
【发布时间】:2020-10-02 20:50:59
【问题描述】:

我有一个存档页面,其中显示与作者相关的产品。但是我使用的小部件只允许我选择“当前查询”,并且只向我显示作者产品的完整列表,而无法编辑更多功能。

我有兴趣编辑要显示的产品数量并能够按特色产品进行过滤。

我看到它允许我从 ID 链接自定义查询过滤器,但我不明白如何构建代码以使其工作。我会给你一个例子来说明代码是如何的,但这种情况是帖子的。


    // Showing multiple post types in Posts Widget
add_action( 'elementor/query/my_custom_filter', function( $query ) {
    // Here we set the query to fetch posts with
    // post type of 'custom-post-type1' and 'custom-post-type2'
    $query->set( 'post_type', [ 'custom-post-type1', 'custom-post-type2' ] );
} );

【问题讨论】:

    标签: php wordpress woocommerce product elementor


    【解决方案1】:

    如果该操作确实存在,那么过滤作者所需要做的就是在作者部分设置一个查询参数,可用的选项有:

    (取自https://developer.wordpress.org/reference/classes/wp_query/#author-parameters这里)

    author (int) – use author id.
    author_name (string) – use ‘user_nicename‘ – NOT name.
    author__in (array) – use author id (available since version 3.7).
    author__not_in (array) – use author id (available since version 3.7).
    

    所以你应该这样做:

    $query->set( 'author_name', 'my_author_nicename' );
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-05
      • 1970-01-01
      • 1970-01-01
      • 2016-02-16
      相关资源
      最近更新 更多