1

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.

6
  • Do yout get nothing or the Not Found message? Do you have refreshed your permalinks after registration?
    – fuxia
    Mar 28, 2011 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, 2011 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?
    – fuxia
    Mar 28, 2011 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, 2011 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, 2011 at 10:53

2 Answers 2

9

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?

2
  • 1
    Just FYI I had to do this on 3.8. My custom post types are using the default post_tag.
    – kel
    Dec 20, 2013 at 23:24
  • Same here, using 3.9.
    – gosukiwi
    Jul 4, 2014 at 18:55
0

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; ?>
1
  • I'm sorry my questions was worded poorly I'll fix it.
    – Wyck
    Mar 28, 2011 at 5:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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