自定义帖子类别正在相互融合

时间:2018-08-27 07:00:55

标签: wordpress

我在网站上创建了2个自定义帖子,现在的问题是,当我在第一个自定义帖子中创建任何类别时,它会自动添加到第二个自定义帖子中,我希望每个自定义帖子都具有单独的类别。

也许我在创建自定义帖子时做错了什么??

请帮助...

下面是代码

function create_posttype()
{
    register_post_type( 'case_study',

        array(
            'labels' => array(
                'name' => __( 'Case Study' ),
                'singular_name' => __( 'Case Study' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'case_study'),
            'taxonomies' => array('category'),
            'supports' => array( 'title','thumbnail', 'revisions', 'custom-fields','editor', 'post-templates', 'related-post', 'thumbnail','excerpt'),
        )
    );

    register_post_type( 'healthcare',

        array(
            'labels' => array(
                'name' => __( 'Health care' ),
                'singular_name' => __( 'Health care' )
            ),
            'public' => true,
            'has_archive' => true,
            'rewrite' => array('slug' => 'healthcare'),
            'taxonomies' => array('category'),
            'supports' => array( 'title','thumbnail', 'revisions', 'custom-fields','editor', 'post-templates', 'related-post', 'thumbnail','excerpt'),
        )
    );
}

// Hooking up our function to theme setup
add_action( 'init', 'create_posttype' );

function add_case_meta_boxes() {
    add_meta_box("case_contact_meta", "case_study", "add_contact_details_team_meta_box", "case_study", "normal", "low");
}
function add_contact_details_team_meta_box()
{
    global $post;
    $custom = get_post_custom( $post->ID );
?>
    <p>
        <label>Designation: </label><br />
        <input type="text" name="designation" value="<?= @$custom["designation"][0] ?>" class="width99" />
    </p>
    <p>

    <?php
}

function save_case_custom_fields(){
  global $post;

  if ( $post )
  {
    update_post_meta($post->ID, "designation", @$_POST["designation"]);
  }
}
add_action( 'admin_init', 'add_case_meta_boxes' );
add_action( 'save_post', 'save_case_custom_fields' );

/****************/

function add_healthcare_meta_boxes() {
    add_meta_box("healthcare_contact_meta", "healthcare", "add_healthcare_meta_box", "healthcare", "normal", "low");
}
function add_healthcare_meta_box()
{
    global $post;
    $custom = get_post_custom( $post->ID );
?>
    <p>
        <label>Designation: </label><br />
        <input type="text" name="designation" value="<?= @$custom["designation"][0] ?>" class="width99" />
    </p>
    <p>

    <?php
}

function save_healthcare_custom_fields(){
  global $post;

  if ( $post )
  {
    update_post_meta($post->ID, "designation", @$_POST["designation"]);
  }
}
add_action( 'admin_init', 'add_healthcare_meta_boxes' );
add_action( 'save_post', 'save_healthcare_custom_fields' );

预先感谢...... :-)

0 个答案:

没有答案