0

I've associated a taxonomy to pages and a custom_post_type.

When i'm on a page with a said taxonomy term, I need to display a list of custom_post_type associated twith the same term.

I'm using this:

<?php
    $args = array(
        'post_type' => 'offres', //my CPT
        'post_status' => 'publish',
        'tax_query' => array(
            array(
                'taxonomy' => 'cible', //my Custom Taxonomy
                'field' => 'id',
                'include_children' => false,
            )
        )
    );
    $_query = new WP_Query($args);

    if ($_query->have_posts()):
        while ($_query->have_posts()):
            $_query->the_post();

            the_title();
        endwhile;
    endif;

    wp_reset_query();?>

I need to get the current taxonomy term or id from the page, how do I this?

2
  • Do not run a custom query, just use the default loop in order to display the correct posts from the main query Jul 23, 2015 at 13:06
  • I don't think I understand hom i'm supposed to use the default loop here. I've tried a lot of ways but nothing gets me the result I want, do you have an exemple? Jul 23, 2015 at 15:14

1 Answer 1

0

use some thing like this

$queried_object = get_queried_object();
$term_id = $queried_object->term_id;

Most probably $term_id should give the id of the taxonomy term of the current page, try echo $term_id;

If it doesn't then try using var_dump() like

echo "<pre>";var_dump( $queried_object )echo "</pre>";

Analyse the output , and use it according to your need

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.