I'm trying to implement tags on my pages, so pages show up in the tag clouds I have printing in various places on the site.

The problem? If I tag a page, it doesn't show up in the list. Only posts do. I'm using the following in my functions.php to enable page tags:

// add tag support to pages
function tags_support_all() {
register_taxonomy_for_object_type('post_tag', 'page');

// ensure all tags are included in queries
function tags_support_query($wp_query) {
if ($wp_query->get('tag')) $wp_query->set('page_type', 'any');

// tag hooks
add_action('init', 'tags_support_all');
add_action('pre_get_posts', 'tags_support_query');

My tag.php page has the following:

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

<h2 class="category-title" id="post-<?php the_ID(); ?>"><a href="<?php the_permalink() ?    >" rel="bookmark" title="Permanent Link to <?php the_title(); ?>" style="color:#000;"><?php     the_title(); ?></a></h2>
 <?php the_excerpt(); ?>

<?php if ($wp_query->max_num_pages > 15) : ?>
 <nav class="post-nav">
<ul class="pager">
  <li class="previous"><?php next_posts_link(__('&larr; Older posts', 'roots')); ?>      </li>
  <li class="next"><?php previous_posts_link(__('Newer posts &rarr;', 'roots')); ?>   </li>

  • Is that all you have on the tag.php page? – eteich Jan 29 '14 at 21:17
  • In functions.php, should $wp_query->set('page_type', 'any') be $wp_query->set('post_type', 'any') instead? – Pat J Jan 29 '14 at 21:36

You need to use pre_get_posts hook. Paste this code to your themes functions.php file.

add_action('pre_get_posts', 'wpse_pre_get_posts');
function wpse_pre_get_posts($q)
    if( $q->is_main_query() && $q->is_tag() )
        $q->set('post_type', array('post','page') );
  • DANG - that worked. I have no idea what it's doing, but it worked. Thank you! – theater eleven Jan 30 '14 at 0:04
  • That filter should be returning data, or be an action instead. – t31os Jan 30 '14 at 8:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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