向不起作用的相关帖子添加过滤器

时间:2013-01-23 作者:Anagio

我正在使用下面的过滤器按作者筛选相关帖子,我添加了一个作者ID进行测试,但它们不是按作者筛选的

add_filter( \'woocommerce_product_related_posts\', \'woo_custom_attribute_filter\' );
function woo_custom_attribute_filter( $q ) {

            array(
            \'orderby\'        => \'rand\',
            \'posts_per_page\' => $limit,
            \'post_type\'      => \'product\',
            \'author\'        => 2,
            \'fields\'         => \'ids\',
            \'meta_query\'     => $meta_query,
            \'tax_query\'      => array(
                \'relation\'      => \'OR\',
                array(
                    \'taxonomy\'     => \'product_cat\',
                    \'field\'        => \'id\',
                    \'terms\'        => $cats_array
                ),
                array(
                    \'taxonomy\'     => \'product_tag\',
                    \'field\'        => \'id\',
                    \'terms\'        => $tags_array
                )
            )
        );
    //print_r($q);
    return $q;
}

1 个回复
最合适的回答,由SO网友:diggy 整理而成

$q 应包含数组:

add_filter( \'woocommerce_product_related_posts\', \'woo_custom_attribute_filter\', 10, 1 );
function woo_custom_attribute_filter( $q ) {
    $q = array( /* args here */ );
    return $q;
}

结束