1

I have a custom post type "news_updates" which I have not given custom tags or categories. I have however created a normal tag (not attached to a custom post type), and assigned it to a particular news_updates single post. The tag shows up in the tag list when viewing the post.

However, while I have permalinks set to %postname%, when attempting to find all posts assigned this tag, or any tag, it yields a 404 error. When I set permalinks to default, this isn't an issue, and the tag archive returns fine.

I have no idea why this is, as the name of the tag isn't even remotely close to any of my custom post types or taxonomies, I have tried changing the permalinks settings back and forth, refreshing, flush_rewrite_rules. Nothing worked except changing the permalinks back to default.

Here is the code for my custom post type. I'm not using any plugins to create my post types or taxonomies.

function custom_post_news_updates() { 
// creating (registering) the custom type 
register_post_type( 'news_updates', /* (http://codex.wordpress.org/Function_Reference/register_post_type) */
    // let's now add all the options for this post type
    array('labels' => array(
        'name' => __('News Update Posts', 'jointstheme'), /* This is the Title of the Group */
        'singular_name' => __('News Update', 'jointstheme'), /* This is the individual type */
        'all_items' => __('All News Update Post', 'jointstheme'), /* the all items menu item */
        'add_new' => __('Add New', 'jointstheme'), /* The add new menu item */
        'add_new_item' => __('Add New News Update', 'jointstheme'), /* Add New Display Title */
        'edit' => __( 'Edit', 'jointstheme' ), /* Edit Dialog */
        'edit_item' => __('Edit News Update', 'jointstheme'), /* Edit Display Title */
        'new_item' => __('New News Update', 'jointstheme'), /* New Display Title */
        'view_item' => __('View News Update', 'jointstheme'), /* View Display Title */
        'search_items' => __('Search News Update', 'jointstheme'), /* Search Custom Type Title */ 
        'not_found' =>  __('Nothing found in the Database.', 'jointstheme'), /* This displays if there are no entries yet */
        'not_found_in_trash' => __('Nothing found in Trash', 'jointstheme'), /* This displays if there is nothing in the trash */
        'parent_item_colon' => ''
        ), /* end of arrays */
        'description' => __( 'This is where News and Updates posts go.', 'jointstheme' ), /* Custom Type Description */
        'public' => true,
        'publicly_queryable' => true,
        'exclude_from_search' => false,
        'show_ui' => true,
        'query_var' => true,
        'menu_position' => 4, /* this is what order you want it to appear in on the left hand side menu */ 
        'menu_icon' => get_stylesheet_directory_uri() . '/library/images/custom-post-icon.png', /* the icon for the custom post type menu */
        'rewrite'   => false,//array( 'slug' => 'news-updates', 'with_front' => false ), /* you can specify its url slug */
        'has_archive' => 'news-updates-archive', /* you can rename the slug here */
        'capability_type' => 'post',
        'hierarchical' => false,
        /* the next one is important, it tells what's enabled in the post editor */
        'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'comments', 'revisions', /*'sticky'*/)
    ) /* end of options */
); /* end of register post type */

//these both make it so the custom post type can use the global categories and tags
/* this adds your post categories to your custom post type */
register_taxonomy_for_object_type('category', 'news_updates');
/* this adds your post tags to your custom post type */
register_taxonomy_for_object_type('post_tag', 'news_updates');
} 


add_action( 'init', 'custom_post_news_updates');

Any help appreciated. I've searched, but to no avail.

3
  • Are your permalinks set to postname or %postname% ? – Privateer Jan 26 '15 at 23:59
  • %postname% -- sorry, just didn't feel like typing out the % symbols :) @Privateer – Josh Burson Jan 27 '15 at 0:08
  • I like how well you have commented your code. Makes it really easy to understand and to follow. You get my upvote for that :-) – Pieter Goosen Jan 27 '15 at 6:29
1

Try give a name for your rewrite, like so:

'rewrite' => array(
    'slug'       => 'news-updates-archive',
    'with_front' => true,
    'feeds'      => false,
    'pages'      => true,
)

So you will avoid any problem.

Also, the last functions you're using are unnecessary. You can setup it on register_post_type:

'taxonomies' => array('post_tag', 'category'),

PS: Try empty your trash also and double check if your custom post type name is not duplicated. Sometimes that's the error.

8
  • That didn't work. That's actually how I set up all my custom post types to begin with, but I had to set rewrite to false in order to get single posts to work – Josh Burson Jan 27 '15 at 19:12
  • Try using this plugin to inspect your Rewrites Rules: wordpress.org/plugins/rewrite-rules-inspector Also, a plugin to re-rewrite easily permalinks for custom post types is the wordpress.org/plugins/custom-post-type-permalinks Hope it helps – Leo Caseiro Jan 28 '15 at 1:45
  • Good recommendation, I see a bunch of missing rewrite rules for tag, type, and category (see here: i.imgur.com/Zti67lx.png ) -- question is, what do I do now? I tried flushing rewrite rules, but they still are missing. – Josh Burson Jan 28 '15 at 18:05
  • I discovered I can add these rewrite rules manually to my functions.php, and when I add the four missing entries on the list for tags, the entries still end up being "missing", however they jump to the bottom of the list, as though Wordpress recognizes them as being written, but then loses them again or something. I put: add_action('init', 'a_function_that_has_the_four_different_rewrite_rules_for_tags'); -- any idea why they get moved down on the list, but still are missing? Still 404ing – Josh Burson Jan 28 '15 at 18:58
  • You must try your URL without rewrite just to check if it's working properly or not, like so: url.com/index.php?custom_cat_newspub=25 PS:make sure you change the id from 25 to and ID you have. It it's not working, you should deactivate plugins, some functions.php you might have in your plugin and identify where have a conflict. Try flush the permalinks as you change the plugins and functions.php – Leo Caseiro Jan 29 '15 at 6:02
0

There was a stray flush_rewrite_rules() in my functions.php, commenting it out made everything work properly. From there I just had to include the custom post type's posts in the archives page, a la http://css-tricks.com/snippets/wordpress/make-archives-php-include-custom-post-types/

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.