prefix . Globals::ATUM_PRODUCT_DATA_TABLE; $unmng_join = (array) apply_filters( 'atum/get_unmanaged_products_legacy/join_query', array( "LEFT JOIN $wpdb->postmeta AS mt1 ON (posts.ID = mt1.post_id AND mt1.meta_key = '_manage_stock')", "LEFT JOIN $atum_data_table AS apd ON (posts.ID = apd.product_id)", ) ); $post_statuses = current_user_can( 'edit_private_products' ) ? [ 'private', 'publish' ] : [ 'publish' ]; // TODO: Change the query to remove the subquery and get the values with joins. if ( $get_stock_status ) { $unmng_fields[] = "(SELECT meta_value FROM $wpdb->postmeta WHERE post_id = posts.ID AND meta_key = '_stock_status' ) AS stock_status"; } $unmng_where = array( "WHERE posts.post_type IN ('" . implode( "','", $post_types ) . "')", "AND posts.post_status IN ('" . implode( "','", $post_statuses ) . "')", "AND (mt1.post_id IS NULL OR mt1.meta_value = 'no')", 'AND apd.inheritable != 1', // Exclude the inheritable products from query (as are just containers in ATUM List Tables). ); $unmng_where = apply_filters( 'atum/get_unmanaged_products_legacy/where_query', $unmng_where ); $sql = 'SELECT DISTINCT ' . implode( ',', $unmng_fields ) . "\n FROM $wpdb->posts posts \n" . implode( "\n", $unmng_join ) . "\n" . implode( "\n", $unmng_where ); return $wpdb->get_results( $sql, ARRAY_N ); // WPCS: unprepared SQL ok. } }