First of all TagPages uses register_taxonomy_for_object_type
since its first release.
Nevertheless, tag pages in themes will still only include posts. – You could probably call this a bug in WordPress…
Berny
Berny’s script is very well commented, much more so than most; it’s worth picking through to see how it works.
No, I don’t dispute that. It’s well written. 🙂
What I’m confused about is why pages don’t show up on a tag query… I see this code in WP_Query which I believe is meant to make this work:
> if ( $this->is_tax ) {
> if ( empty($post_type) ) {
> $post_type = ‘any’;
If this really is broken, is there a Core trac bug for this?
Second, even if WordPress did this wrong by default, doesn’t using a filter like query_vars
to overtly specify the post_types we’re looking for work? I just don’t get yet why all the SQL filters are necessary.
True, I also thought this would be set to any, but apparently it doesn’t. 😉 I remember having some discussions about tagging of pages on the forums when WordPress 2.3 came out, but the core devs refused to include this functionality.
So there’s maybe also a historical reason why the post_type for taxonomy queries is automatically set to post. – I didn’t debug the code, though. – If you like to you can file a ticket in trac… Btw. this also applies for the custom column which holds the tags in edit.php for pages.
Anyway, you’re right that the extension of the post-types can also be done with a filter on the query_vars rather than modifying the SQL query itself. Cheers for this tip. 🙂
Here’s the code I’ve worked out. – It should also cover the possibility of custom post-type with post-tags scenarios. Maybe you can have a look. – If you like to, I can also send you the reworked plugin by mail.
add_filter('pre_get_posts', array(&$this, 'add_page_to_tags_query'));
function add_page_to_tags_query($query) {
if (is_tag() && !is_admin()) {
/*
if the post_type does not exist,
we create it
*/
if (!array_key_exists('post_type', $query->query_vars))
$query->query_vars['post_type']=array();
/*
if post_type is set to or includes
any or page
there's nothing more to do
*/
if (!empty($query->query_vars['post_type']) && (in_array('any', (array) $query->query_vars['post_type']) || (in_array('page', (array) $query->query_vars['post_type']))))
return $query;
/*
otherwise include post and page
into post_type
*/
$query->query_vars['post_type']=array_unique(array_merge((array) $query->query_vars['post_type'], array('post', 'page')));
}
return $query;
}
Starting from version 1.40, TagPages uses the $wp_query
object instead of modifying the SQL query for post-tags archive-pages.
greetz,
Berny