Solved

Get posts in custom taxonomy category?

Posted on 2014-09-09
1
174 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

So you have coded your own WordPress plugin and now you want to allow users to upload images to a folder in the plugin folder rather than the default media location? Follow along and this article will show you how to do just that!
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The purpose of this video is to demonstrate how to update a WordPress Site’s version. WordPress releases new versions of its software frequently and it is important to update frequently in order to keep your site secure, and to get new WordPress…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

930 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

13 Experts available now in Live!

Get 1:1 Help Now