WordPress

EDD Custom Query Based on Term

Easy Digital Download The Most Popular WordPress plugin for selling Digital Goods. If you want to sell Digital product like Code Snippets, Premium Themes , Software then Easy Digital Download is really awesome. Over 475,000 people is using the plugin for their own store. You can learn more about Easy Digital Download from their web site .

Last week I had worked on EDD Template for one my client and its really awesome. I am now going to share some Query Tricks with EDD so you can learn something really amazing.

Include posts from the selected category with the category ID – EDD Query

 

<?php
/**
 * $args will display posts from terms 
 * 			
 * 			Includes posts from term ID 7
 *
 * @var array
 * @since 1.0.5
 * @author devstrend.com
 */
$args = array(
		'post_type'      => 'download',
		'posts_per_page' => '1', 
			//you can define post per page or -1 for unlimited view ( All Post View )
		'tax_query'      => array(
					'relation' => 'AND',
						//Include posts from the selected category with the category ID
					array(
						'taxonomy' => 'download_category',
						'field'    => 'id',
						'terms'    => 7, // Just making query from the category with the ID 7
					),
				)
);
	    
$aa_homeblog = new WP_Query( $args ); ?>

 

Include posts from the selected categories with thecategories ID – EDD Query

 

<?php
/**
 * $args will display posts from terms 
 * 			
 * 			Includes posts from term ID 5,6
 *
 * @var array
 * @since 1.0.5
 * @author devstrend.com
 */
$args = array(
		'post_type'      => 'download',
		'posts_per_page' => '1', 
			//you can define post per page or -1 for unlimited view ( All Post View )
		'tax_query'      => array(
					'relation' => 'AND',
						//Include posts from the multiple selected categories with the categories ID (2category with ID 5 and 6)
					array(
						'taxonomy' => 'download_category',
						'field'    => 'id',
						'terms'    => array( 5,6 ), // Just making query from the multiple category (2category with ID 5 and 6)
					),
				)
);
	    
$aa_homeblog = new WP_Query( $args ); ?>

 

Excludes posts from the selected category with the category ID – EDD Query

 

<?php
/**
 * $args will display posts from terms 
 * 			
 * 			Exclude posts from term ID 7
 *
 * @var array
 * @since 1.0.5
 * @author devstrend.com
 */
$args = array(
		'post_type'      => 'download',
		'posts_per_page' => '1', 
			//you can define post per page or -1 for unlimited view ( All Post View )
		'tax_query'      => array(
					'relation' => 'AND',
						//Exclude posts from the selected category with the category ID
					array(
						'taxonomy' => 'download_category',
						'field'    => 'id',
						'terms'    => 7, //It will show all products except from the following category.
						'operator' => 'NOT IN',
					),
				)
);
	    
$aa_homeblog = new WP_Query( $args ); ?>

 

Excludes posts from the selected categories with the categories ID – EDD Query

 

<?php
/**
 * $args will display posts from terms 
 * 			
 * 			Exclude posts from term ID 5,6
 *
 * @var array
 * @since 1.0.5
 * @author devstrend.com
 */
$args = array(
		'post_type'      => 'download',
		'posts_per_page' => '1', 
			//you can define post per page or -1 for unlimited view ( All Post View )
		'tax_query'      => array(
					'relation' => 'AND',
						//Exclude posts from the selected Multiple categories with the categories ID
					array(
						'taxonomy' => 'download_category',
						'field'    => 'id',
						'terms'    => array( 5,6 ), //It will show all products except from the following categories.
						'operator' => 'NOT IN',
					),
				)
);
	    
$aa_homeblog = new WP_Query( $args ); ?>

 

Include posts from the selected category with the category slug – EDD Query

 

<?php
/**
 * $args will display posts from terms 
 * 			
 * 			Includes posts from term Slug
 *
 * @var array
 * @since 1.0.5
 * @author devstrend.com
 */
$args = array(
		'post_type'      => 'download',
		'posts_per_page' => '1', 
			//you can define post per page or -1 for unlimited view ( All Post View )
		'tax_query'      => array(
					'relation' => 'AND',
						//Include posts from the selected categories with the categories Slug
					array(
						'taxonomy' => 'download_category',
						'field'    => 'slug',
						'terms'    => array( wordpress,themes ), // Just making query from the categories with the Slug
					),
				)
);
	    
$aa_homeblog = new WP_Query( $args ); ?>

I hope it will help you on your project for EDD Custom Query. Let me know if there you need any help from me aboutEDD Custom Query. If you like my writing please share my post.

 

You Might Also Like

One comment

Leave a Reply