custom Taxonomy breaks tags
-
hello,
I am modifying a child of the starkers theme to create a portfolio site. I am trying to use a custom post type for the individual items. that works well but now I want to add a custom taxonomy so I can filter them. I found the code I needed on line, and when I put it in functions.php it works, and the menu item shows up on the left side menu bar. but now I have run into two problems.- The first is that now if I go to the “Tags” menu item for regular posts, and click view under a tag, I get the 404 page. if I remove the custom taxonomy but leave the custom post type. this problem goes away and I am able to and a page listing all posts with that tag shows up, as it should. does anyone know why that is? or how I can fix it?
- The second problem is that with the custom taxonomy code left in. When I go to the link that is created under the custom post type I can create new “tags” like I should be able to (little T because they are created under the custom post type and not under regular posts, IDK if that makes a difference). I can then go edit the custom posts add add the tags to them just like on regular posts. so far so good. when I go back to the custom “tags” page the “tags” say on the right side that they were applied to x number of posts. just like they are supposed to. however at this point if I click on view (it pops up under the “tag” when you hover) the page is found but it says that there are no posts in that section. ?????? I don’t understand, in the admin section it says there are posts but the front says there aren’t. have I missed something?
sorry for the long post. I can’t give you a lnik because the site is on a local xampp server.
here is the code I used:
<?php add_action( 'init', 'create_project_taxonomies', 0 ); function create_project_taxonomies() { // Initialize New Taxonomy Labels $labels = array( 'name' => _x( 'Tags', 'taxonomy general name' ), 'singular_name' => _x( 'Tag', 'taxonomy singular name' ), 'search_items' => __( 'Search Types' ), 'all_items' => __( 'All Tags' ), 'parent_item' => __( 'Parent Tag' ), 'parent_item_colon' => __( 'Parent Tag:' ), 'edit_item' => __( 'Edit Tags' ), 'update_item' => __( 'Update Tag' ), 'add_new_item' => __( 'Add New Tag' ), 'new_item_name' => __( 'New Tag Name' ), ); // Custom taxonomy for Project Tags register_taxonomy('tag',array('project'), array( 'hierarchical' => false, 'labels' => $labels, 'show_ui' => true, 'query_var' => true, )); } /*--- Creating custom post type for project --*/ add_action('init', 'project_custom_init'); /*-- Custom Post Init Begin --*/ function project_custom_init() { $labels = array( 'name' => _x('Projects', 'post type general name'), 'singular_name' => _x('Project', 'post type singular name'), 'add_new' => _x('Add New', 'project'), 'add_new_item' => __('Add New Project'), 'edit_item' => __('Edit Project'), 'new_item' => __('New Project'), 'view_item' => __('View Project'), 'search_items' => __('Search Projects'), 'not_found' => __('No projects found'), 'not_found_in_trash' => __('No projects found in Trash'), 'parent_item_colon' => '', 'menu_name' => 'Project' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => true, 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'supports' => array('title','editor','author','thumbnail','excerpt','comments'), 'menu_icon' => ICON_PATH . '/images/icons/portfolio_1_16.png', ); // The following is the main step where we register the post. register_post_type('project',$args); } //'taxonomies' => array('post_tag'), /*-- Custom Post Init Ends --*/ // Add filter to ensure the text Project, or project, is displayed when a user updates a project add_filter('post_updated_messages', 'project_updated_messages'); function project_updated_messages( $messages ) { global $post, $post_ID; $messages['project'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __('Project updated. <a href="%s">View project</a>'), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('Project updated.'), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf( __('Project restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __('Project published. <a href="%s">View project</a>'), esc_url( get_permalink($post_ID) ) ), 7 => __('Project saved.'), 8 => sprintf( __('Project submitted. <a target="_blank" href="%s">Preview project</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('Project scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview project</a>'), // translators: Publish box date format, see https://php.net/date date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('Project draft updated. <a target="_blank" href="%s">Preview project</a>'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); return $messages; } // Styling for the custom post type icon function project_header() { global $post_type; ?> <style> <?php if (($_GET['post_type'] == 'project') || ($post_type == 'project')) : ?> #icon-edit { background:transparent url('<?php echo ICON_PATH .'/images/icons/portfolio_1_32_hover.png';?>') no-repeat; } <?php endif; ?> </style> <?php } add_action('admin_head', 'project_header'); ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘custom Taxonomy breaks tags’ is closed to new replies.