• toniweb

    (@toniweb)


    I am trying to add another field (subtitle) to my already created and existing custom post_type: team (code from functions.php in my childtheme)

    <?php
    /**
     * Custom Post type register framework
     */
    include(get_stylesheet_directory(). '/inc/acpt/init.php');
    add_action('init', 'makethem');
    function makethem() {
        $args = array(
            'supports' => array( 'title', 'editor', 'page-attributes', 'thumbnail', 'excerpt'  ),
            'hierarchical' => true,
        );
    
        $team = new post_type('team','team', false,  $args );
    
    }
    
    /**
     * Initialize the metabox class
     */
    add_action( 'init', 'be_initialize_team_meta_boxes', 9999 );
    function be_initialize_team_meta_boxes() {
        if ( !class_exists( 'team_Meta_Box' ) ) {
            require_once( get_stylesheet_directory(). '/inc/metaboxes/fisio-metaboxes.php' );
            require_once( get_stylesheet_directory(). '/inc/metaboxes/init.php' );
    
        }
    }
    ?>

    And this is the code in fisio-metaboxes.php

    <?php
    /**
     * Include and setup custom metaboxes and fields.
     *
     * @category YourThemeOrPlugin
     * @package  Metaboxes
     * @license  https://www.opensource.org/licenses/gpl-license.php GPL v2.0 (or later)
     * @link     https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress
     */
    
    /**
     * Define the metabox and field configurations.
     *
     * @param  array $meta_boxes
     * @return array
     */
     add_filter( 'team_Meta_Box', 'team_sample_metaboxes' );
    function team_sample_metaboxes( array $meta_boxes ) {
        $prefix = '_team_';
        $meta_boxes[] = array(
                'id'         => 'team_details',
                'title'      => 'Team details',
                'post_type'      => 'team', // Post type
                'context'    => 'side',
                'priority'   => 'high',
                'show_names' => true, // Show field names on the left
                'fields'     => array(
                    array(
                        'name' => 'Subtitle',
                        //'desc' => '',
                        'id' => $prefix . 'subtitle',
                        'type' => 'text'
                    ),
                ),
            );
        return $meta_boxes;
    }
    
    add_action( 'init', 'team_initialize_team_meta_boxes', 9999 );
    /**
     * Initialize the metabox class.
     */
    function team_initialize_team_meta_boxes() {
    
        if ( ! class_exists( 'team_Meta_Box' ) )
            require_once get_stylesheet_directory(). '/inc/metaboxes/init.php';
    
    }

    The problem is that when in the wp-admin i whant to add a new team’s post_type post, the post_type doesn’t have the subtitle field

    What am I missing?

  • The topic ‘How to add a addional field to a custom post_type’ is closed to new replies.