Wordpress paginate_links() function, 404s and trouble - wordpress

This has been a horrendous, crippling, time stealing (two week) horrible horrible problem.
It might be rewriting, my use of custom posts, but after stripping out so much (and reducing some functionality of my theme) I've reduced my problem to this:
paginate_links() is putting out a link like this:
?s=cute&post_type=image&paged=2
When I changed the variable in the browser bar to page=2 (dropping the 'd').
?s=cute&post_type=image&page=2
It works correctly.
So my question reduced to this: If I must get that function to output the "page" variable properly, how is that done?
paged and paged are both used by WordPress. So conversely, how do I get paged recognized if that is better practice?
For all I know, this is indicative of some deeper issue I have in my theme, but for the life of me I can't see how else I could be going wrong!
EDIT:
Here is my code I'm using:
if ( get_query_var('paged') )
$paged = get_query_var('paged');
elseif ( get_query_var('page') )
$paged = get_query_var('page');
else
$paged = 1;
$big = 999999999; // need an unlikely integer
$stuff_to_echo = paginate_links( array(
'base' => str_replace( $big, '%#%', esc_url( get_pagenum_link( $big ) ) ),
'format' => '?page=%#%',
'current' => max( 1, $paged ),
'total' => $wp_query->max_num_pages,
'type' => 'array'
) );
EDIT 2 - If above is good, here is another possible area the problem might be happening. I'll post the creation of the custom post type and the rewrite rules -
//image custom post type
add_action( 'init', 'symbiostock_image_manager_register' );
function symbiostock_image_manager_register( )
{
//creating custom post type for image
$labels = array(
'name' => 'Symbiostock Images',
'singular_name' => 'Image',
'add_new' => 'New Image',
'add_new_item' => 'Add New Image',
'edit_item' => 'Edit Image',
'new_item' => 'New Image',
'all_items' => 'All Images',
'view_item' => 'View Image',
'search_items' => 'Search Images',
'not_found' => 'No image found',
'not_found_in_trash' => 'No images found in Trash',
'parent_item_colon' => '',
'menu_name' => 'RF Images'
);
$args = array(
'labels' => $labels,
'singular_label' => __( 'Image' ),
'description' => 'Image Listings',
'menu_position' => 100,
'menu_icon' => symbiostock_IMGDIR . '/symbiostock_icon2.png',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'capability_type' => 'post',
'hierarchical' => true,
'has_archive' => true,
'exclude_from_search' => false,
'supports' => array(
'title',
'editor',
'thumbnail'
),
'rewrite' => array(
'slug' => 'image',
'with_front' => false
)
);
register_post_type( 'image', $args );
register_taxonomy( 'image-type', array(
'image'
), array(
'hierarchical' => true,
'label' => 'Image Categories',
'singular_label' => 'Image Type',
'rewrite' => true,
'exclude_from_search' =>false,
'public' => true,
'slug' => 'image-type'
) );
register_taxonomy( 'image-tags', array(
'image'
), array(
'hierarchical' => false,
'rewrite' => true,
'query_var' => true,
'singular_label' => 'Image Keyword',
'hierarchical' => false,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => true,
'update_count_callback' => '_update_post_term_count',
'slug' => 'image-tag',
'labels' => array(
'name' => _x( 'Image Keywords', 'taxonomy general name' ),
'singular_name' => _x( 'Keywords', 'taxonomy singular name' ),
'search_items' => __( 'Search Images' ),
'all_items' => __( 'All Image Keywords' ),
'edit_item' => __( 'Edit Image Keyword' ),
'update_item' => __( 'Update Image Keyword' ),
'add_new_item' => __( 'Add New Image Keyword' ),
'new_item_name' => __( 'New Keyword Name' ),
'menu_name' => __( 'Image Keywords' ),
),
'rewrite' => array(
'slug' => 'search-images', // This controls the base slug that will display before each term
'with_front' => false,
'hierarchical' => false
),
) );
}
add_action( 'admin_init', 'symbiostock_image_directory' );
function symbiostock_image_directory( )
{
add_meta_box( 'symbiostock-image-meta', 'Symbiostock Image Info', 'symbiostock_image_manager_meta_options', 'image', 'normal', 'high' );
}
And here are the rewrite rules further down -
add_action( 'init', 'symbiostock_rewrite' );
function symbiostock_rewrite( )
{
global $wp_rewrite;
$wp_rewrite->add_permastruct('typename','typename/%year%%postname%/' , true , 1);
add_rewrite_rule('typename/([0-9]{4})/(.+)/?$','index.php?typename=$matches[2]', 'top');
$wp_rewrite->flush_rules();
}

I know this is old but I've had the same problem and solved it by changing the permalink of the page that was causing the 404.
This is because, apparently, you cannot have a page-slug with the same name as your custom post type.
All credit goes to Ryan S. for sharing the original solution: http://www.sutanaryan.com/2013/09/404-error-in-custom-post-type-pagination-wordpress/

Under your args for paginate_links() I would ensure that you have your format set properly. 'paged' is typically used for obtaining the "current page" the user is on (Reference: https://codex.wordpress.org/Pagination#Adding_the_.22paged.22_parameter_to_a_query)
'format' => '?page=%#%'
it sounds like you have it set to '?paged=%#%'
Here is a complete example
global $wp_query;
$args = array(
'format' => '?page=%#%',
'current' => max( 1, get_query_var('paged') ),
'total' => $wp_query->max_num_pages
);
paginate_links($args);

It might not be the most elegant solution, but is appropriate in this case.
I simply set up a redirect to the taxonomy page in the event someone is searching this post type.
add_action( 'parse_query', 'image_search_redirect' );
function image_search_redirect( $query ) {
if ( ( is_search() && get_query_var( 'post_type' ) == 'image' ) ) {
wp_redirect(home_url("?image-tags=") . urlencode(get_query_var('s')));
exit();
}
}
This is not as much a solution as a creative work-around. There should be no reason why I get a 404 not found on the "paged=" variable. If some future person knows a better solution I'd love to know one!

Related

When I add custom post type permalink rewrite, my regular post permalinks stop working. Can't get both to work at the same time

really struggling with this one, so any help would be much appreciated. My site has both regular post posts, and a custom post type called "articles."
I'm trying to get it to work so that my regular posts will use the /%category%/postname%/ permalink structure, (which I have set up in settings). This is working fine, until I add a custom rewrite for my article post type. I'd like articles to follow a /%issue%/%postname%/ structure. I can get this working great with the following:
add_filter( 'post_type_link', 'wpa_show_permalinks', 1, 2 );
function wpa_show_permalinks( $post_link, $id = 0 ){
$post = get_post($id);
if ( is_object( $post ) && $post->post_type == 'article' ){
$terms = wp_get_object_terms( $post->ID, 'issue_tax' );
if( $terms ){
return str_replace( '%issue%' , $terms[0]->slug , $post_link );
}
}
return $post_link;
}
where my post type is registered like this:
function article_post_type() {
$labels = array(
'name' => _x( 'Magazine Articles', 'Post Type General Name', 'text_domain' ),
'singular_name' => _x( 'Magazine Article', 'Post Type Singular Name', 'text_domain' ),
'menu_name' => __( 'Magazine Articles', 'text_domain' ),
'name_admin_bar' => __( 'Magazine Articles', 'text_domain' ),
'parent_item_colon' => __( 'Parent Article:', 'text_domain' ),
'all_items' => __( 'All Articles', 'text_domain' ),
'add_new_item' => __( 'Add New Article', 'text_domain' ),
'add_new' => __( 'Add New', 'text_domain' ),
'new_item' => __( 'New Article', 'text_domain' ),
'edit_item' => __( 'Edit Article', 'text_domain' ),
'update_item' => __( 'Update Article', 'text_domain' ),
'view_item' => __( 'View Article', 'text_domain' ),
'search_items' => __( 'Search Article', 'text_domain' ),
'not_found' => __( 'Not found', 'text_domain' ),
'not_found_in_trash' => __( 'Not found in Trash', 'text_domain' ),
);
$rewrite = array(
'slug' => '%issue%',
'with_front' => false,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'article', 'text_domain' ),
'description' => __( 'Magazine Articles and Features', 'text_domain' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'trackbacks', 'revisions', 'custom-fields', 'page-attributes', ),
'taxonomies' => array( 'issue_tax', 'category', 'featured_media', 'tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'menu_icon' => 'dashicons-welcome-write-blog',
'show_in_admin_bar' => true,
'show_in_nav_menus' => true,
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'page',
);
register_post_type( 'article', $args );
}
add_action( 'init', 'article_post_type', 0 );
I add that, reset permalink settings, and the article permalinks start working as indended - BUT - as soon as I get that working, my regular posts start displaying a 404.
Why am I unable to get both to work at the same time? Am I missing a piece somewhere?
Thanks for any advice!
-erin
Just a follow up to my question - perhaps the thing that I'm really struggling with is why is the post_type_filter function affecting more than just the article post type that I have specified?
Thanks,
Erin
Ok, one more super strange thing. This all works if I pass a query parameter at the end of my custom post links, so this works: http://www.mysitename.com/spring-2015/test-article-here/?post_type=article but this gives me a 404 http://www.mysitename.com/spring-2015/test-article-here/
Why would that be? I'm sorry for so many questions, just really trying to get to the bottom of this..!
Thanks again,
Erin
Replace 'slug' => '%issue%', with 'slug' => 'article/%issue%',
It will definitely work, I have tested it. Kindly note that "article" is the post type name.
Also Save permalinks after making above change.
From the answer above:
Replace: Replace 'slug' => '%issue%', with 'slug' => 'article/%issue%',
That didn't work fully for me, so I had to change my post_type_link filter as well.
All I had to do was to change following:
return str_replace( '%issue%' , $terms[0]->slug , $post_link );
With:
return str_replace( 'article/%issue%' , $terms[0]->slug , $post_link );
It's a bit strange and I spent several hours figuring this out. Hope it helps someone in the future!

WordPress Custom Type append Post ID at the end

I've been searching for two days know and tried almost every example I've seen online but the real problem is that all examples have different post-type-names or want different results in general.
That's why I want to ask for help and start from scratch.
I've created a Custom Post Type for listing some Jobs opportunities but because most job-titles have the same name (product designer) I would like to prevent WordPress from adding -1, -2, -3, -4 after each slug over time and that's why I was thinking about adding the %post_id% behind the %post-name% for only this new custom post type.
A post_id should be an unique number so that would prevent ugly urls in the long run.
This is what I have, only the post type setup, but right now I think I need to work with rewrites and stuff.
function jobs() {
$labels = array(
'name' => _x( 'Jobs', 'Post Type General Name', 'theme-name' ),
'singular_name' => _x( 'Job', 'Post Type Singular Name', 'theme-name' ),
'menu_name' => __( 'Jobs', 'theme-name' ),
'parent_item_colon' => __( 'Parent Job:', 'theme-name' ),
'all_items' => __( 'All Jobs', 'theme-name' ),
'view_item' => __( 'View Job', 'theme-name' ),
'add_new_item' => __( 'Add New Job', 'theme-name' ),
'add_new' => __( 'Add New', 'theme-name' ),
'edit_item' => __( 'Edit Job', 'theme-name' ),
'update_item' => __( 'Update Job', 'theme-name' ),
'search_items' => __( 'Search Job', 'theme-name' ),
'not_found' => __( 'Not found', 'theme-name' ),
'not_found_in_trash' => __( 'Not found in Trash', 'theme-name' ),
);
$rewrite = array(
'slug' => 'vacatures',
'with_front' => false,
'pages' => false,
'feeds' => false,
);
$args = array(
'label' => __( 'vacatures', 'theme-name' ),
'description' => __( 'Post Type Description', 'theme-name' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'thumbnail', 'revisions', 'custom-fields', ),
'taxonomies' => array( 'category' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => false,
'show_in_admin_bar' => false,
'menu_position' => 9,
'menu_icon' => 'dashicons-welcome-learn-more',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'rewrite' => $rewrite,
'capability_type' => 'post',
);
register_post_type( 'vacatures', $args );
}
// Hook into the 'init' action
add_action( 'init', 'jobs', 0 );
any help would be so thankful!
EDIT
I'm a bit further now and I have a feeling I'm getting close to what I need.
I've added the code below and the result is almost good. It appends the post_id on the end of the slug only problem it's twice/double.
I want this:
http://example.com/vacatures/product-designer/123/
But instead it does this:
http://example.com/vacatures/product-designer/123/123/
function fix_permalink( $post_link, $id = 0 ) {
add_rewrite_rule(
'^vacatures/',
'index.php?post_type=vacatures&p=',
'top'
);
$post = get_post($id);
if ( is_wp_error($post) || $post->post_type != 'vacatures' ) {
return $post_link;
}
empty ( $post->slug )
and $post->slug = sanitize_title_with_dashes( $post->post_title );
return home_url( user_trailingslashit( "vacatures/$post->slug/$post->ID" ) );
}
add_filter( 'post_type_link', 'fix_permalink' );
Looking at your code, it looks as though you've rewritten the slug to imitate the post ID and yet in the last line of code you state the new permalink should be the post_type followed by the slug (which is now the ID) followed by the ID (the reason for the double).
I did a few tests and indeed either removing the slug or ID from the new permalink structure it did remove the duplicate. But I could not get the_permalink() to correctly link to a single view of my custom post type post (Eg. within an archive page using 'the_permalink()' did not link to my single.php for that post type), so I cannot say that I could get your code to work for me.
But I have been using this snippet for a while and it does what you'd like.
Your rewrite:
'rewrite' => array( 'slug' => 'vacatures' )
The function:
// Rewrite permalink structure
function vacatures_rewrite() {
global $wp_rewrite;
$queryarg = 'post_type=vacatures&p=';
$wp_rewrite->add_rewrite_tag( '%cpt_id%', '([^/]+)', $queryarg );
$wp_rewrite->add_permastruct( 'vacatures', '/vacatures/%cpt_id%/', false );
}
add_action( 'init', 'vacatures_rewrite' );
function vacatures_permalink( $post_link, $id = 0, $leavename ) {
global $wp_rewrite;
$post = &get_post( $id );
if ( is_wp_error( $post ) )
return $post;
$newlink = $wp_rewrite->get_extra_permastruct( 'vacatures' );
$newlink = str_replace( '%cpt_id%', $post->ID, $newlink );
$newlink = home_url( user_trailingslashit( $newlink ) );
return $newlink;
}
add_filter('post_type_link', 'vacatures_permalink', 1, 3);
New permalinks structure is: http://domain.com/vacatures/208/
I hope this helps you.

Custom post type won't display, IS homepage & main query

I have a custom post type that worked just fine earlier, but not anymore. I haven't installed any new plugins and my code seems perfectly valid. Other custom fields are showing (default post type), but the ones I'm talking about not anymore.
Here's the code:
// Show posts of 'post', 'homepage_slider' post types on home page
add_action( 'pre_get_posts', 'add_my_post_types_to_query' );
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'homepage_slider' ) );
return $query;
}
As you can guess, homepage_slider is my Custom Post Type. I haven't tweaked it's code one bit, but here it is just for reference:
function homepage_slider() {
$labels = array(
'name' => 'Images',
'singular_name' => 'Image',
'menu_name' => 'Homepage Slider Images',
'parent_item_colon' => 'Parent Image:',
'all_items' => 'All images',
'view_item' => 'View Image',
'add_new_item' => 'Add New Image',
'add_new' => 'Add New',
'edit_item' => 'Edit Image',
'update_item' => 'Update Image',
'search_items' => 'Search Image',
'not_found' => 'Not found',
'not_found_in_trash' => 'Not found in Trash',
);
$args = array(
'label' => 'homepage_slider',
'description' => 'Homepage Slider',
'labels' => $labels,
'supports' => array( 'title', 'thumbnail' ),
// 'taxonomies' => array( 'category', 'post_tag' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => 'myurl',
'can_export' => true,
'has_archive' => false,
'exclude_from_search' => true,
'publicly_queryable' => true,
'rewrite' => false,
'capability_type' => 'page',
);
register_post_type( 'homepage_slider', $args );
}
// Hook into the 'init' action
add_action( 'init', 'homepage_slider', 0 );
I have queried both the fact that it is indeed the homepage and the main query is indeed running. Really weird error.
Any suggestions?
EDIT: I think something's wrong with the add_my_post_types_to_query function as it's not working with another Custom Post Type either.
Try replacing:
function add_my_post_types_to_query( $query ) {
if ( is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'homepage_slider' ) );
return $query;
}
With:
function add_my_post_types_to_query( $query ) {
if ( $query->is_home() && $query->is_main_query() )
$query->set( 'post_type', array( 'post', 'homepage_slider' ) );
return $query;
}
Okay, so here's how I fixed it. Not quite a natural fix, but it did the job.
I simply created a new loop that runs through the custom post type wherever it must be placed and repeat for every other custom field I have on the homepage.
:)

Custom Taxonomy Links For Custom Post Types Not Working

I have set up a custom post type and a custom taxonomy. Then I am displaying the list of taxonomies as a set of links so that if someone clicks on that link, it should bring up all the posts under that taxonomy. Currently this is not working. It keeps taking me to the 404 page with the 'This is somewhat embarrassing isn't it?' message.
Code is as follows:
FUNCTIONS.PHP
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'companies', 'companies', array( 'hierarchical' => true, 'label' => 'Company Categories', 'query_var' => true, 'rewrite' => true ) );
}
add_action('init', 'register_mypost_type');
function register_mypost_type() {
register_post_type('companies',array(
'labels' => array(
'name' => 'Companies',
'singular_name' => 'Company',
'add_new' => 'Add New Company',
'add_new_item' => 'Add New Company',
'edit_item' => 'Edit Company',
'new_item' => 'Add New Company',
'view_item' => 'View Company',
'search_items' => 'Search Companies',
'not_found' => 'No companies found',
'not_found_in_trash' => 'No companies found in trash'
),
'public' => true,
'supports' => array( 'title', 'editor', 'thumbnail', 'excerpt'),
'capability_type' => 'post',
'rewrite' => array('slug' => 'companies'),
'taxonomies' => array('category'),
'menu_position' => 7,
'has_archive' => true,
'hierarchical' => false
));
}
Then on another page called 'page-company.php' I use the following code to output the list of taxonomies as links:
<?php
$args = array( 'taxonomy' => 'companies' );
wp_list_categories( $args );
?>
When I hover over one of these links the URL is displayed as:
'http://localhost:81/?companies=graphic-design'
Graphic Design being one of the categories I have added to my custom taxonomy.
However clicking this link always takes me to the 404 page.
I have set up an archives page called archive-companies.php and I thought all of this would do the trick.
Any help that anyone can provide would be greatly appreciated.
Thanks in advance.
OMG OMG OMG ... after days reading posts on how to solve the issue, using rewrite rules and ussing permalinks rewriting code, your solution was the only one that worked perfectly!
The only change I needed to apply was in the custom taxonomy declaration:
This code
'rewrite' => array(
'slug' => 'pubs/type',
'with_front' => false
),
for this code
'rewrite' => true,
and that was it. Working like a charm!
Note:
Prior to my re-writing I tested your code and also got a 404.
1) I re-wrote you your custom post type and used your custom companies category.
2) Then I cycled from default to /%postname%/ and it works.
Functions.php
Here you go the custom post type:
// Register Custom Post Type
function register_mypost_type() {
$labels = array(
'name' => _x( 'Companies', 'Post Type General Name' ),
'singular_name' => _x( 'Company', 'Post Type Singular Name' ),
'menu_name' => __( 'Company' ),
'parent_item_colon' => __( 'Parent Company'),
'all_items' => __( 'All Companies'),
'view_item' => __( 'View Company'),
'add_new_item' => __( 'Add New Company'),
'add_new' => __( 'New Company'),
'edit_item' => __( 'Edit Company'),
'update_item' => __( 'Update Company' ),
'search_items' => __( 'Search companies' ),
'not_found' => __( 'No companies found' ),
'not_found_in_trash' => __( 'No companies found in Trash'),
);
$rewrite = array(
'slug' => 'company',
'with_front' => true,
'pages' => true,
'feeds' => true,
);
$args = array(
'label' => __( 'company'),
'description' => __( 'Companies Posts' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'revisions', ),
'taxonomies' => array( 'companies' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 100,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'query_var' => 'company',
'rewrite' => $rewrite,
'capability_type' => 'post',
);
register_post_type( 'company', $args );
}
add_action( 'init', 'register_mypost_type', 0 );
Your custom category
add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies() {
register_taxonomy( 'companies', 'companies', array( 'hierarchical' => true, 'label' => 'Company Categories', 'query_var' => true, 'rewrite' => true ) );
}
First of all create taxonomy-companies.php template in the root directory of your theme. This template will be responsible for displaying your taxonomy term posts.
then on that template you need to use the get_queried_object() to get all the taxonomy details.
e.g;
$queries_obj = get_queried_object();
echo '<pre>';
print_r( $queries_obj );
echo '</pre>';
it will return
WP_Term Object
(
[term_id] => 10
[name] => Featured companies
[slug] => featured-companies
[term_group] => 0
[term_taxonomy_id] => 10
[taxonomy] => companies-category
[description] =>
[parent] => 0
[count] => 2
[filter] => raw
)
then query posts like below.
$q = new WP_Query( array(
'post_type' => 'companies', // post type name
'posts_per_page' => get_option( 'posts_per_page' ),
'tax_query' => array(
array(
'taxonomy' => $queries_obj->taxonomy,
'field' => 'term_id',
'terms' => array( $queries_obj->term_id )
)
)
) );
if ( $q->have_posts() ) :
while ( $q->have_posts() ) :
$q->the_post();
// loop do stuf
the_title();
endwhile;
wp_reset_query();
endif;

Trying to get both custom post type and posts to show up in tag and category pages

I've built a custom post type, that is set to use the out-of-the-box tags and categories that posts use. However, if I click on a tag or category link, the archive only shows posts with that tag, not my custom post type. I've tried a few ways to fix it but they don't seem to be working. My code is:
// Add Resource Post Type
add_action('init', 'hallam_init');
function hallam_init() {
// set up the labels
$labels = array(
'name' => _x('Resources', 'post type general name'),
'singular_name' => _x('Resource', 'post type singular name'),
'add_new' => _x('Add New', 'resource'),
'add_new_item' => __( 'Add New Resource' ),
'edit_item' => __( 'Edit Resource' ),
'new_item' => __( 'New Resource' ),
'view_item' => __( 'View Resource' ),
'search_items' => __( 'Search Resources' ),
'not_found' => __( 'No resources found' ),
'not_found_in_trash' => __( 'No respources found in Trash' ),
'parent_item_colon' => ''
);
// set up the args
$args = array (
'labels' => $labels,
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array (
'slug' => 'resources'
),
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 5,
'supports' => array(
'title',
'editor',
'author',
'thumbnail',
'excerpt',
'comments'
),
'taxonomies' => array(
'collection',
'category',
'post_tag'
),
'has_archive' => true
);
register_post_type('ht_resource', $args);
}
// Add Taxonomy
register_taxonomy('collection', 'ht_resource', array(
'hierarchical' => true,
'label' => 'Collections',
'query_var' => true,
'rewrite' => true
));
// Fix the archives
add_filter( 'pre_get_posts', 'add_to_query' );
function add_to_query( $query ) {
// if ( is_home() ) {
if( $query->query_vars['suppress_filters'] ) // TODO check if necessary
return $query;
$supported = $query->get( 'post_type' );
if ( !$supported || $supported == 'post' )
$supported = array( 'post', 'ht_resource' );
elseif ( is_array( $supported ) )
array_push( $supported, 'ht_resource' );
$query->set( 'post_type', $supported );
return $query;
//}
}
Am I missing something obvious?
Can you plz try this by adding on your theme's functions.php? Hope it will work
function query_post_type($query) {
if(is_tag()) {
$query->set('post_type',$post_types=get_post_types('','names'));
return $query;
}
}
add_filter('pre_get_posts', 'query_post_type');
thnx

Resources