Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Query posts by taxonomies & custom field WordPress

I am looking to organize some posts from an "Employment" CPT. Each post would be a new job, example "Manager, Customer Services".

I need to organize all of the posts by Company, and then by a Location, and then by a "Closing Date". Any posts that that are past the "Closing Date" should not be displayed.

Company & Location are taxonomies.

Closing Date is a datepicker custom field that is saved in unix time.

It should look something like this:

Company A - Location 1
- Manager, Customer Services
- Manager, Human Resources
- Manager, Sales

Company A - Location 2
- Manager, Sales
- Manager, Human Resources

Company B - Location 1
- Manager, Human Resources

Company B - Location 1
- Manager, Sales
- Manager, Human Resources
- Manager, Customer Services


Any suggestions?

Answers (3)

2013-07-23

Arnav Joy answers:

so locations are sub child of parent term company ?


Anthony Moore comments:

Location is it's own taxonomy.

2013-07-23

Susanta K Beura answers:

Hi Anthony Moore,

I will be happy to help you. I can be reached via skype at susanta.k (Susanta K Beura).

Thank you.

Susanta K Beura
email: [email protected]


Anthony Moore comments:

Please let me know what other info you may need. Hoping to have the question answered on here so that other people may benefit from it :)

2013-07-23

Hariprasad Vijayan answers:

Try this method,

$args = array(
'meta_key' => 'Closing Date',
'meta_value' => date( 'ymd'),
'meta_compare' => '>='
'tax_query' => array(
'relation' => 'AND',
array(
'taxonomy' => 'company',
'field' => 'slug',
'terms' => array('company-a')
)
array(
'taxonomy' => 'location',
'field' => 'slug',
'terms' => array('location-1')
)
)
);
$query = new WP_Query( $args );


Anthony Moore comments:

Hello, Thanks for your suggestion.

With your code, how would I get posts from "Company B" and "Location 1"? I think the query needs to be a bit more dynamic to return all of the results.


Hariprasad Vijayan comments:

Let me know where you want to display this result. Or show me the working site


Hariprasad Vijayan comments:

<?php
// Company array
$company = array('company-a'); // You can replace this value with company-a or company-b...
$location = array('location-1'); //You can replace this value with location-1 or location-2...
$args = array(

'meta_key' => 'Closing Date',

'meta_value' => date( 'ymd'),

'meta_compare' => '>='

'tax_query' => array(

'relation' => 'AND',

array(

'taxonomy' => 'company',

'field' => 'slug',

'terms' => $company

)

array(

'taxonomy' => 'location',

'field' => 'slug',

'terms' => $location

)

)

);

$query = new WP_Query( $args );
?>