Solved

Get posts in custom taxonomy category?

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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article discusses how to create an extensible mechanism for linked drop downs.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
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…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

696 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