0

I'm using the the filter below to filter related posts by author, I added an author ID to test but they are not filtering by author

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 Answer 1

1

$q should contain the array:

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.