0

I have setup a custom taxonomy called "video_categories" and have set it to two different custom post types - "videos" and "locations".

I am using the template "taxonomy-video_categories.php" to display the posts that have related taxonomys but I would only like to display the post type "videos" and exclude the post type "locations".

Tunaki
  • 132,869
  • 46
  • 340
  • 423
Liam O'Toole
  • 29
  • 2
  • 6

1 Answers1

0

You can simply use query_posts to alter the main loop.

Put the following code before have_posts call :

global $query_string;
query_posts( $query_string . '&post_type=video' );

A proper way for doing this is to hook into pre_get_posts :

query_posts() is the easiest, but not preferred or most efficient, way to alter the default query that WordPress uses to display posts. Use query_posts() to display different posts than those that would normally show up at a specific URL. (The preferred way is hooking into 'pre_get_posts' and altering the main query that way using is_main_query)

soju
  • 25,111
  • 3
  • 68
  • 70
  • What would look like the code inside a `pre_get_posts` hook ? I mean, how do you make to not specify the video post_type to the unrelated queries? – Frank6 Apr 04 '16 at 21:31