• Resolved Erfan MHDi

    (@erfanmhd)


    hi,

    i’d like to query and show post that “IS” or “IS NOT” inside of any Bundle Product on Entire Site.

    how can filter these posts?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Pratik Jain

    (@pratik-jain)

    Hi @erfanmhd

    You can do something like this.

    1) First query the EDD Bundle products.
    2) Fetch its meta “_edd_bundled_products”. This will give you the list of all products.
    3) So gather them in one array, unique it and display as you want.

    The reason is there are no flag set at individual post that it is a part of any bundle.

    OR there is one another method that you can query the EDD Simple Product and loop of it.

    In Loop you have to check that particular product is in a bundle or not with minimum query.

    Thread Starter Erfan MHDi

    (@erfanmhd)

    hi @pratik-jain,

    Thanks for your response,
    This is my code so far,

    $MusicAlbumArg = array ( 
    	'post_type' 		=> 'download',
    	'post_status' 		=> array( 'publish' ),
    	'orderby' 		=> 'date', 
    	'order' 		=> 'desc',
    	'posts_per_page' 	=> 1,
    	'ignore_sticky_posts'	=> true,
    	'meta_query' => array(
    		array(
    			'key' 	=> '_edd_product_type',
    			'value' => 'bundle',
    			'compare' => '=',
    		),
    		array(
    			'key' 	=> '_edd_bundled_products',
    			'value' => ':"' . get_the_ID() . '";',
    			'compare' => 'LIKE',
    		)
    	)
    );

    this will return the parent bundle product name that current product is a child of.
    i want to filter EDD Product and ONLY show product that is not a child of ANY parent bundle product.

    can i get more help with second array (_edd_bundled_products) to finish the code with you ?

    Hi @erfanmhd

    First, here we get the products which are in bundle.

    The below query will get the bundle products.

    $MusicAlbumArg = array ( 
    	'post_type' 		=> 'download',
    	'post_status' 		=> array( 'publish' ),
    	'orderby' 		=> 'date', 
    	'order' 		=> 'desc',
    	'posts_per_page' 	=> 20,
    	'ignore_sticky_posts'	=> true,
    	'meta_query' => array(
    		array(
    			'key' 	=> '_edd_product_type',
    			'value' => 'bundle',
    			'compare' => '=',
    		)
    	)
    );

    Now loop of it and get the meta : $bundle_products = get_post_meta( $post->ID, '_edd_bundled_products', true );

    This will give array of products ID. Store it in array and gather it. There are the products which are in bundle. I hope this helps.

    Thread Starter Erfan MHDi

    (@erfanmhd)

    Thanks for your response,

    the problem is whatever i do i cannot exclude the product that are inside any bundle and list the posts that are NOT in any bundle products.

    $MusicAlbumArg = array ( 
    	'post_type' 		=> 'download',
    	'post_status' 		=> array( 'publish' ),
    	'orderby' 		=> 'date', 
    	'order' 		=> 'desc',
    	'posts_per_page' 	=> 20,
    	'ignore_sticky_posts'	=> true,
    	'meta_query' => array(
    		array(
    			'key' 	=> '_edd_product_type',
    			'value' => 'bundle',
    			'compare' => '=',
    		)
    	)
    );

    Above code will list all bundles and this one :
    $bundle_products = get_post_meta( $post->ID, '_edd_bundled_products', false );
    if i change true to false will keep an array of posts that are not listed in any bundle product i suppose.

    sry if i’m asking too much but can you help me loop trough it please ?
    i want to query posts that are not listed in any bundle product and exclude any post that is inside any bundle product from query.

    Thanks a lot man ??

    Hi @erfanmhd

    $all_bundle_products = array();
    $MusicAlbumArg = array ( 
    	'post_type' 		=> 'download',
    	'post_status' 		=> array( 'publish' ),
    	'orderby' 		=> 'date', 
    	'order' 		=> 'desc',
    	'posts_per_page' 	=> 20,
    	'ignore_sticky_posts'	=> true,
    	'meta_query' => array(
    		array(
    			'key' 	=> '_edd_product_type',
    			'value' => 'bundle',
    			'compare' => '=',
    		)
    	)
    );
    
    $query = new WP_Query( $MusicAlbumArg );
    
    if( $query->have_posts() ) {
    	while ( $query->have_posts() ) : $query->the_post();
    
    		$bundle_products = get_post_meta( $post->ID, '_edd_bundled_products', true );
    
    		if( ! empty( $bundle_products ) ) {
    			$all_bundle_products = array_merge( $bundle_products, $all_bundle_products );
    		}
    
    	endwhile;
    
    	$all_bundle_products = array_unique( $all_bundle_products );
    }
    
    wp_reset_postdata(); // Reset WP Query

    $all_bundle_products will give you all the products ID which are in bundle.

    Now you have to run an another query and exclude these IDS from query so that will give you IDS which are not included in any bundle ??

    Because there have not been any recent updates to this topic we’ll be changing the status to resolved. If you have any further questions you can start a new thread, or head over to our support page to submit your request if it is related to one of our available add-ons.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Query Post that is child of any Bundle’ is closed to new replies.