Product::related_products( array $args = array() )
Summary
Get a list of products related to this one
Parameters
- $args
-
(array) (Optional) Additional args to pass to WP_Query
Default value: array()
Return
(int[]) The IDs of related products
Source
File: src/BigCommerce/Post_Types/Product/Product.php
'posts_per_page' => 10, 'post_status' => 'publish', 'order' => 'ASC', 'orderby' => 'title', ] ); $args = array_merge( $args, [ 'post_type' => Product::NAME, 'fields' => 'ids', 'suppress_filters' => false, 'post__not_in' => [ $this->post_id ], ] ); $related_meta = $this->get_property( 'related_products' ); if ( empty( $related_meta ) || ! is_array( $related_meta ) ) { // User has explicitly set it to hide related products /** * This filter is documented in src/BigCommerce/Post_Types/Product/Product.php */ return apply_filters( 'bigcommerce/product/related_products', [], $this->post_id ); } $related_meta = array_map( 'intval', $related_meta ); if ( in_array( - 1, $related_meta ) ) { // User has set it to automatically calculate related products /** * This filter is documented in src/BigCommerce/Post_Types/Product/Product.php */ return apply_filters( 'bigcommerce/product/related_products', $this->related_products_by_category( $args ), $this->post_id ); } $args['bigcommerce_id__in'] = $related_meta; $related_products = array_map( 'intval', get_posts( $args ) ); /** * Filter the related products to display for the current product * * @param int[] $related The IDs of related product posts * @param int $current The current post ID */ return apply_filters( 'bigcommerce/product/related_products', $related_products, $this->post_id ); } /**