WC_Product_Data_Store_CPT::get_related_products( array $cats_array, array $tags_array, array $exclude_ids, int $limit, int $product_id )

Return a list of related products (using data like categories and IDs).


Description Description


Parameters Parameters

$cats_array

(Required) List of categories IDs.

$tags_array

(Required) List of tags IDs.

$exclude_ids

(Required) Excluded IDs.

$limit

(Required) Limit of results.

$product_id

(Required) Product ID.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/data-stores/class-wc-product-data-store-cpt.php

	public function get_related_products( $cats_array, $tags_array, $exclude_ids, $limit, $product_id ) {
		global $wpdb;

		$args = array(
			'categories'  => $cats_array,
			'tags'        => $tags_array,
			'exclude_ids' => $exclude_ids,
			'limit'       => $limit + 10,
		);

		$related_product_query = (array) apply_filters( 'woocommerce_product_related_posts_query', $this->get_related_products_query( $cats_array, $tags_array, $exclude_ids, $limit + 10 ), $product_id, $args );

		// phpcs:ignore WordPress.VIP.DirectDatabaseQuery.DirectQuery, WordPress.DB.PreparedSQL.NotPrepared
		return $wpdb->get_col( implode( ' ', $related_product_query ) );
	}

Top ↑

Changelog Changelog

Changelog
Version Description
3.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.