Solved

Get posts in custom taxonomy category?

Posted on 2014-09-09
1
167 Views
Last Modified: 2014-09-19
Hi,

I want to get posts in custom taxonomy category, I have code below but it show nothing, could you please check it for me? I want to get post with slug events in wg_category

$args=array(
	'post_type' => wg_get_deal_post_type(),
	'post_status' => 'publish',
	'paged' => $paged,
	'tax_query'	=> array(
		array(
			'taxonomy'  => 'wg_category',
			'field'     => 'slug',
			'terms'     => 'events',
			),
		),
	'meta_query' => array(
		array(
			'key' => '_expiration_date',
			'value' => array(0, current_time('timestamp')),
			'compare' => 'BETWEEN'
		)),
);

Open in new window


And I also want a code to not display featured on other query, is the code 'operator'  => 'NOT IN' correct?
$args=array(
	'post_type' => wg_get_deal_post_type(),
	'post_status' => 'publish',
	'paged' => $paged,
	'tax_query'	=> array(
		array(
			'taxonomy'  => 'wg_category',
			'field'     => 'slug',
			'terms'     => 'featured',
			'operator'  => 'NOT IN'
			),
		),
	'meta_query' => array(
		array(
			'key' => '_expiration_date',
			'value' => array(0, current_time('timestamp')),
			'compare' => 'BETWEEN'
		)),
);

Open in new window


Thank you
0
Comment
Question by:Pham Trung Kien
1 Comment
 
LVL 15

Accepted Solution

by:
eemit earned 500 total points
ID: 40311856
- Check what is returned by: wg_get_deal_post_type()

- tax_query:
	'tax_query'	=> array(
		array(
			'taxonomy'  => 'wg_category',
			'field'     => 'slug',//use 'slug' with 'terms' as cat slugs
			'terms'     => array( 'my_cat_1', 'my_cat_2' ),//here your custom category slugs,
			)
		),

Open in new window

     //or
	'tax_query'	=> array(
		array(
			'taxonomy'  => 'wg_category',
			'field'     => 'term_id',//use 'term_id' with 'terms' as cat ID-s
			'terms'     => array( 5, 7 ),//here your custom category ID-s,
			)
		),

Open in new window

>is the code 'operator'  => 'NOT IN' correct?
Yes, possible values for operator are 'IN'(default), 'NOT IN', 'AND'.
but try:
	'terms'     => array( 'featured' ),

Open in new window

instead of
	'terms'     => 'featured',

Open in new window


- Try what you get without 'meta_query'
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Do you think that WordPress is just for blogs?  Think again!  WordPress is really a fantastic all around platform that you can use to develop websites on.  Integrated into its basic functionality is the ability to create pages using your choice of a…
WordPress can be pretty daunting, especially for a beginner, so I thought it might be a good idea to write an article to show how easy it is to get started in WordPress and to design a custom theme.  The first step is to check with your hosting comp…
The purpose of this video is to demonstrate how to Import and export files in WordPress. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: mywebsite.com/wp-login.php : Click on Too…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now