1

I have registered a taxonomy called location - I have then created a taxonomy file called taxonomy-location.php which is fine and returns all the terms within that taxonomy.

Say I have a 2 terms one called London and the other called Birmingham - I am able to do this:

$property = array( 'post_type' => 'properties');
$loop = new WP_Query(array(
    'post_type' => $property,
    'tax_query' => array(
        'relation' => 'AND',
        array(
            'taxonomy' => 'location',
            'field'    => 'slug',
            'terms'    => 'london'
        ),
    ),
));

but when I head to the Birmingham term it only returns results for London - which is expected because I set the term to London for all of them.

My question is how do I make it only return only that taxonomy term?

Extra Info: I am registering my Custom Post Type and Taxonomies inside a Plugin

4
  • 3
    The main query will contain posts associated to whatever term you are viewing, you don't have to query for them yourself.
    – Milo
    Apr 11, 2016 at 15:38
  • @Milo Hmmm... that's strange for mine if I went to example.com/location/London it would display all the Birmingham ones aswell
    – Stephen
    Apr 11, 2016 at 16:21
  • You should be replacing the main query with a custom one, ever. It create much more issues than solving one. You should take your time and read this Apr 12, 2016 at 4:20
  • @PieterGoosen Yh I have gotten rid of that now and made an archive-property.php page and that stops me from altering the query, this is like my first time making a big theme with a lot of different custom post type so I'm still learning as I go along :) :D
    – Stephen
    Apr 12, 2016 at 6:20

0

Browse other questions tagged or ask your own question.