Community Forums › Forums › Archived Forums › Design Tips and Tricks › Custom Post Type Question
This topic is: not resolved
- This topic has 1 reply, 1 voice, and was last updated 8 years, 5 months ago by Tmgale.
Viewing 2 posts - 1 through 2 (of 2 total)
-
AuthorPosts
-
November 5, 2015 at 8:01 am #170208TmgaleMember
Hi all,
I have currently used code to assign my CPTs a parent page. After this is done it all works fine, a meta box appears in the edit page and it allows me to enter a page id that I wish to be the CPTs parent.
However, after I go forwards with this my CPT page pulls up a 404 error.
I have tried the following:
Saving permalinks to flush permalinks.
Here is the code I use to create the page parent relationship,
//Add the meta box callback function function admin_init(){ add_meta_box("case_study_parent_id", "Case Study Parent ID", "set_case_study_parent_id", "casestudy", "normal", "low"); } add_action("admin_init", "admin_init"); //Meta box for setting the parent ID function set_case_study_parent_id() { global $post; $custom = get_post_custom($post->ID); $parent_id = $custom['parent_id'][0]; ?> <p>Please specify the ID of the page or post to be a parent to this Case Study.</p> <p>Leave blank for no heirarchy. Case studies will appear from the server root with no assocaited parent page or post.</p> <input type="text" id="parent_id" name="parent_id" value="<?php echo $post->post_parent; ?>" /> <?php // create a custom nonce for submit verification later echo '<input type="hidden" name="parent_id_noncename" value="' . wp_create_nonce(__FILE__) . '" />'; } // Save the meta data function save_case_study_parent_id($post_id) { global $post; // make sure data came from our meta box if (!wp_verify_nonce($_POST['parent_id_noncename'],__FILE__)) return $post_id; if(isset($_POST['parent_id']) && ($_POST['post_type'] == "casestudy")) { $data = $_POST['parent_id']; update_post_meta($post_id, 'parent_id', $data); } } add_action("save_post", "save_case_study_parent_id");'
Here is the CPT php code:
And here is my cpt php code:
function register_custom_post_case_study() { $labels = array( 'name' => _x('Case Studies', 'post type general name'), 'singular_name' => _x('Case Study', 'post type singular name'), 'add_new' => _x('Add New', 'Case Study'), 'add_new_item' => __('Add New Case Study'), 'edit_item' => __('Edit Case Study'), 'new_item' => __('New Case Study'), 'view_item' => __('View Case Study'), 'search_items' => __('Search Case Studies'), 'not_found' => __('No Case Studies found'), 'not_found_in_trash' => __('No Case Studies found in Trash'), 'parent_item_colon' => '' ); $args = array( 'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'query_var' => true, 'rewrite' => array('slug' => '', 'with_front' => true), 'capability_type' => 'post', 'hierarchical' => true, 'menu_position' => null, 'supports' => array('title','editor','author','excerpt','page-attributes') ); register_post_type( 'casestudy' , $args ); } add_action('init', 'register_custom_post_case_study');
I cant figure out whats wrong? Is it something to do with my rewrite?
Thanks for any help!
November 9, 2015 at 2:56 am #170536TmgaleMemberIm still struggling with this, does any have any ideas?
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
- The forum ‘Design Tips and Tricks’ is closed to new topics and replies.