Solved

Get posts in custom taxonomy category?

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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
In order to have all security and back ups taken care of, WordPress users can sign up for services with WP Engine.
This video teaches users how to migrate an existing Wordpress website to a new domain.
The purpose of this video is to demonstrate how to Test the speed of a WordPress Website. Site Speed is an important metric of a site’s health. Slow site speed can result in viewers leaving your site quickly and not seeing your content. This…

831 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