getting posts from custom taxonomy
-
I read the wordpress codex and it said I could use wp_query and tax_query parameters to bring post that are in that taxonomy but it doesn’t seem to be filtering correctly, it still brings back all the posts I asked for.
here’s my code
$args = array( 'tax_query' => array( 'taxonomy' => $this->taxonomy_name, 'field' => 'slug', 'terms' => $category ), 'post_type' => $this->post_type_name ); $myposts = new WP_Query($args); /* $args output: Array ( [tax_query] => Array ( [taxonomy] => our_works [field] => slug [terms] => commercial ) [post_type] => dlm_works ) */
I did a print_r() on the $mypost->posts variable and it returns the ALL the posts set in the post_type, when I remove the ‘post_type’ => $this->post_type_name filter, it return ALL the posts I have.
I used get_terms on my post just to make sure and here’s the result.
global $post, $dlm_project_var; print_r(get_the_terms($post->ID, $dlm_project_var->taxonomy_name)); /* output: there are two custom posts for that taxonomy 1: Array ( [23] => stdClass Object ( [term_id] => 23 [name] => Websites [slug] => website [term_group] => 0 [term_taxonomy_id] => 23 [taxonomy] => our_works [description] => [parent] => 0 [count] => 1 [object_id] => 239 ) ) 2:Array ( [22] => stdClass Object ( [term_id] => 22 [name] => Commercials [slug] => commercial [term_group] => 0 [term_taxonomy_id] => 22 [taxonomy] => our_works [description] => [parent] => 0 [count] => 1 [object_id] => 205 ) ) */
I have no idea why tax_query isn’t working, I’ve been starring at the codex to make sure I got the syntax right but I still have no clue what’s going on…
Please help
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘getting posts from custom taxonomy’ is closed to new replies.