Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

Query Custom Post Type and Custom Taxonomy Slug WordPress

  • SOLVED

Every "solution" I have found does not work and this is driving me nuts and I know there must be an easy fix for this. I need to query all posts that fall under:

Custom post type: video
Taxonomy: video_type
Type: featurevid

I used the plugin "Custom Post Type UI" to create the post type and taxonomy. I need to have 3 separate queries (different slugs) on the same page if that matters. It doesn't need to be paged. I'm using Wordpress v3.0.5.

Right now I am able to query the post type just fine, but for the life of me cannot query the custom taxonomy slugs.

Thanks for the help!


Answers (2)

2011-02-18

Michael Fields answers:

Ahhh! This problem is indeed a pain in the ____! The problem here is that you are using the word "type" as a taxonomy slug. WordPress does not like this at all. For all I my projects, I have either selected a new term for the taxonomy or I append the taxonomy name to the post_type like "video_type". I know that this is not an ideal solution to your problem, but I have been down this road before and changing the taxonomy's name, slug and/or rewrite value to video_type will get you out of the woods on this. If it is any consolation, you can always use "Type" for the labels.

Best wishes,
-Mike


Lindsey comments:

Ok I changed the taxonomy slug to video_type, now what would the query code be?


Michael Fields comments:

Not sure on exactly what you need to do, but the following code should return an array of post objects for you to work with:
<?php
$videos = get_posts( array(
'post_type' => 'video',
'post_status' => 'publish',
'taxonomy' => 'video_type',
'video_type' => 'featurevid',
) );


Lindsey comments:

I couldn't get your code to work but this did. So thanks for the help.
<?php
query_posts( array( 'video_type' => 'featurevid', 'showposts' => 1 ) ); ?>

2011-02-18

Ivaylo Draganov answers:

Michael is right here - "type" falls into the list of Wordpress reserved terms:
[[LINK href="http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms"]]http://codex.wordpress.org/Function_Reference/register_taxonomy#Reserved_Terms[[/LINK]]

There are a bunch of others as well. And it also seems like [[LINK href="http://www.456bereastreet.com/archive/201012/names_of_wordpress_custom_post_types_must_be_no_longer_than_20_characters/"]]custom post type and taxonomy names are limited to 20 characters[[/LINK]].

As for the query. Something like that:

<?php
query_posts( array(
'post_type' => 'video', // post type
'video_type' => 'featurevid' // taxonomy slug
)
);
?>


Lindsey comments:

That worked, thanks!