LLMS_Voucher::get_products( string $post_type = 'any' )

Get an array of IDs for products associated with this voucher


Description Description


Parameters Parameters

$post_type

(string) (Optional) allows filtering of products by post type

Default value: 'any'


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.voucher.php

	public function get_products( $post_type = 'any' ) {

		global $wpdb;

		$table = $this->get_product_to_voucher_table_name();

		$products = $wpdb->get_col( $wpdb->prepare( "SELECT product_id FROM {$table} WHERE `voucher_id` = %d;", $this->id ) );

		if ( ! empty( $products ) ) {

			// filter any products that don't match the supplied post type
			if ( 'any' !== $post_type ) {
				foreach ( $products as $i => $id ) {
					if ( get_post_type( $id ) !== $post_type ) {
						unset( $products[ $i ] );
					}
				}
			}

			// convert all elements to ints
			$products = array_map( 'intval', $products );

		}

		return $products;
	}

Top ↑

Changelog Changelog

Changelog
Version Description
2.0.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

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





Permalink: