1
votes

I have a query which looks like this:

    <?php
    $args = array( 
      'post_type'=> 'user',
       'showposts'=> -1

       );

        $users = new WP_Query($args);

        echo '<pre>' .print_r($users->posts, 1). '</pre>';

        ?>

The query returns all posts that exist. I now want to add a filter to search by category. Be aware this is custom post type and the categories was a taxonomy.

When i hover over the categories in wordpress it shows the related id's. However when i try to filter by that id, it does not work :(

Any ideas?

1
So what have you tried so far. Add you code even if it does not work as its a place to start from.RiggsFolly
When i hover over one of the categories in Wordpress it says &taxonomy=user_category&tag_ID=17. So i then tried to filter by cat = 17 and i tried tag_id = 17. But neither worked..Planty

1 Answers

3
votes

This will query the posts of "user" type having categories defined by category_user taxonomy of IDs 1, 2 and 3 :

$args = array(
    'post_type'=> 'user',
    'showposts'=> -1,
    'tax_query' => array(
        array(
            'taxonomy' => 'category_user',
            'terms' => array(1,2,3)
        )
    )
);
$users = new WP_Query($args);

Read more : http://codex.wordpress.org/Function_Reference/WP_Query#Taxonomy_Parameters