Solved

Get posts in custom taxonomy category?

Posted on 2014-09-09
1
183 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

Question has a verified solution.

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

Suggested Solutions

Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to exclude a particular blog category from the main blog page. This is can be used when a category already has its own tab, or you simply want certain types of posts not to show up on the main blog. …
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

697 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