Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have registered a custom post type with the right parameters. By that I mean I have added 'taxonomies' => array('post_tag','category'),

I have also tried using register_taxonomy_for_object_type('post_tag', 'custom-post-type-name');

I have a custom function in my functions.php to load a basic loop using a conditional, along the lines of.

function child_maybe_do_grid_loop() {    
if( is_tag() || is_category() || is_archive {
require(CHILD_DIR.'/custom-tag.php');
 }
}

The content of custom-tag.php is just a very basic loop

<?php if (have_posts()) : ?>
 <?php while (have_posts()) : the_post(); ?> 
   <?php the_permalink(); ?>" title="<?php the_title(); ?> 
 <?php endwhile; ?>    
<?php else : ?>
<h2 class="center">Not Found</h2>
<?php endif; ?>

This works fine for regular posts/page tags but for a custom post type tags I get "Not Found".

Any ideas? I assumed a regular simple loop should work with custom posts type tag archives or do I need to put some extra conditionals/query's in there?

** Update toscho's comment made me turn on debugging and in comparison to a working tag page made through a default post, the debug for custom post tag is exactly the same.

I even get count => 2 to show up as I incrementally add more custom posts to the same tag, yet the page refuses to return anything, I am at a loss.

share|improve this question
    
Do yout get nothing or the Not Found message? Do you have refreshed your permalinks after registration? –  toscho Mar 28 '11 at 4:50
    
Actually I do get the "not found", I have refreshed the permalinks, cleared cache, and the tags are showing up for my custom post type in the admin. I should be clear that my conditional statement is in functions.php that loads the basic loop which is in a separate file. –  Wyck Mar 28 '11 at 5:10
    
I had a similar problem recently. The rewrite rules were not applied and I had to add them manually. Did you check this? –  toscho Mar 28 '11 at 5:23
    
Thanks, will do tomorrow getting late here. I should also add this is for a site using the genesis template so I will debug and let you know. –  Wyck Mar 28 '11 at 6:04
    
What's the URL when you're viewing this problem tag archvie? .. Most queries will use a default post type, typically that's post, try explicitly setting the post type parameter for the query. –  t31os Mar 28 '11 at 10:53

2 Answers 2

up vote 6 down vote accepted

Down the rabbit hole..... I found a fix.

From this post Custom Post Type Archives by Date and Taxonomy

Which let me to this trac ticket http://core.trac.wordpress.org/ticket/14589

and the following

function post_type_tags_fix($request) {
    if ( isset($request['tag']) && !isset($request['post_type']) )
    $request['post_type'] = 'any';
    return $request;
} 
add_filter('request', 'post_type_tags_fix');

Maybe this didn't make it into 3.1?

share|improve this answer
1  
Just FYI I had to do this on 3.8. My custom post types are using the default post_tag. –  kel Dec 20 '13 at 23:24
    
Same here, using 3.9. –  gosukiwi Jul 4 at 18:55

You need to run the loop before the conditional statement.

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

<?php if( is_tag() || is_category() || is_archive { ?>

<?php the_permalink(); ?>" title="<?php the_title(); ?> 

<? } else { ?>

//do something else

} ?>

<?php endwhile; ?>    
<?php else : ?>
<h2 class="center">Not Found</h2>
<?php endif; ?>
share|improve this answer
    
I'm sorry my questions was worded poorly I'll fix it. –  Wyck Mar 28 '11 at 5:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.