dozent_get_unattached_courses_to_product( int $exclude_product_id )

Get unattached courses to product


Description

This function return all courses which not attached with any product.


Parameters

$exclude_product_id

(int) (Required)


Return

(array|object|null)


Source

File: includes/integration-functions.php

	function dozent_get_unattached_courses_to_product( $exclude_product_id = 0 ) {
		global $wpdb;

		$exclude_product_sql = '';
		if ( $exclude_product_id ) {
			$exclude_product_sql = " AND meta_value != {$exclude_product_id} ";
		}

		$courses = $wpdb->get_results( " SELECT * FROM {$wpdb->posts} course 
		WHERE post_type = 'dozent_course' 
		AND NOT EXISTS ( 
				SELECT * FROM {$wpdb->postmeta} attached_product 
				WHERE course.ID = attached_product.post_id 
				AND meta_key = '_attached_product_id' {$exclude_product_sql}
			)
	    " );

		return $courses;
	}

Changelog

Changelog
Version Description
DozentLMS 1.0.0 Introduced.