1

I have a custom post type listing

Then there are two custom taxonomies

  1. job_listing_region

  2. job_listing_category

On home page i have links to job_listing_category like shop,eat,stay etc.

and job listing region like himalyan and non-himalyan.

there are two tabs for himalyan and non-himalyan.

Under each tab there are i links to job_listing_category like shop,eat,stay etc.

From there are i want a link to archive page of each of these job_listing_category.

Like if person click on shop under himalyan category then it should get me to archive page where there are posts from shop as well as himalyan

enter image description here How do i acheive this , i have no idea . Please help / give som directions how can i achieve this

1 Answer 1

0

The custom query to get custom post type posts filtered by 2 different terms from 2 different taxonomies will be:

$args = array(
    'post_type' => 'listing',
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'job_listing_region',
            'field'    => 'slug',
            'terms'    => 'himalyan', // this can be an array of terms also
        ),
        array(
            'taxonomy' => 'job_listing_category',
            'field'    => 'slug',
            'terms'    => 'shop', // this can be an array of terms also
        ),
    ),
);

$query = new WP_Query( $args );

Adjust tax_query values to your needs, e.g. pass 'terms' via $variable you get from URL, for example:

$region = get_query_var('job_listing_region');
$args = array(
    ...
    'terms' => $region;
    ...
);

Also, read through Template Hierarchy docs, you should make use of custom post type / custom taxonomy templates, and use pre_get_posts filter to adjust your queries.

3
  • thanks for sharing your view. But the first query you shared , it will give me the posts as i want. But not a link to archive page where this query will display the posts . For this do achieve i need to pass variables to the archive page according to on which link i click. And how do i do that.. i have no idea for now
    – terminator
    Commented Jul 20, 2015 at 11:52
  • That's why I added a link to template hierarchy and mentioned pre_get_posts filter. You can also create a custom template, add some custom rewrite rules. Once you have a working page which uses your custom query and gets proper results, building custom links to this page(s) is not a problem. I'll give you the code a bit later, when I have more time. Meanwhile, check the docs and get familiar with WP_Query, Template Hierarchy, Rewrite Rules, some filters - pre_get_posts, parse_query, template_include. This will help you to understand the code I'll post. Commented Jul 20, 2015 at 12:05
  • okay going to try that
    – terminator
    Commented Jul 20, 2015 at 12:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.