• Hi there,

    Based on the codex, I have started playing with

    wp scaffold post-type movie --label=Movie --theme=twentytwentyone

    I do have the php file created under wp-content/themes/post-types/movie.php

    However there’s no movie post type appearing in the left menu.

    Permalinks refreshed, menu position changed, following parameters verified :

    'public'                => true,
    'hierarchical'          => false,
    'show_ui'               => true,
    'show_in_nav_menus'     => true,

    Am I missing a step?

    Thanks!

    here’s the untouched code inside the php file :

    <?php
    
    /**
     * Registers the <code>movie</code> post type.
     */
    function movie_init() {
    	register_post_type( 'movie', array(
    		'labels'                => array(
    			'name'                  => __( 'Movies', 'twentytwentyone' ),
    			'singular_name'         => __( 'Movie', 'twentytwentyone' ),
    			'all_items'             => __( 'All Movies', 'twentytwentyone' ),
    			'archives'              => __( 'Movie Archives', 'twentytwentyone' ),
    			'attributes'            => __( 'Movie Attributes', 'twentytwentyone' ),
    			'insert_into_item'      => __( 'Insert into Movie', 'twentytwentyone' ),
    			'uploaded_to_this_item' => __( 'Uploaded to this Movie', 'twentytwentyone' ),
    			'featured_image'        => _x( 'Featured Image', 'movie', 'twentytwentyone' ),
    			'set_featured_image'    => _x( 'Set featured image', 'movie', 'twentytwentyone' ),
    			'remove_featured_image' => _x( 'Remove featured image', 'movie', 'twentytwentyone' ),
    			'use_featured_image'    => _x( 'Use as featured image', 'movie', 'twentytwentyone' ),
    			'filter_items_list'     => __( 'Filter Movies list', 'twentytwentyone' ),
    			'items_list_navigation' => __( 'Movies list navigation', 'twentytwentyone' ),
    			'items_list'            => __( 'Movies list', 'twentytwentyone' ),
    			'new_item'              => __( 'New Movie', 'twentytwentyone' ),
    			'add_new'               => __( 'Add New', 'twentytwentyone' ),
    			'add_new_item'          => __( 'Add New Movie', 'twentytwentyone' ),
    			'edit_item'             => __( 'Edit Movie', 'twentytwentyone' ),
    			'view_item'             => __( 'View Movie', 'twentytwentyone' ),
    			'view_items'            => __( 'View Movies', 'twentytwentyone' ),
    			'search_items'          => __( 'Search Movies', 'twentytwentyone' ),
    			'not_found'             => __( 'No Movies found', 'twentytwentyone' ),
    			'not_found_in_trash'    => __( 'No Movies found in trash', 'twentytwentyone' ),
    			'parent_item_colon'     => __( 'Parent Movie:', 'twentytwentyone' ),
    			'menu_name'             => __( 'Movies', 'twentytwentyone' ),
    		),
    		'public'                => true,
    		'hierarchical'          => false,
    		'show_ui'               => true,
    		'show_in_nav_menus'     => true,
    		'supports'              => array( 'title', 'editor' ),
    		'has_archive'           => true,
    		'rewrite'               => true,
    		'query_var'             => true,
    		'menu_position'         => null,
    		'menu_icon'             => 'dashicons-admin-post',
    		'show_in_rest'          => true,
    		'rest_base'             => 'movie',
    		'rest_controller_class' => 'WP_REST_Posts_Controller',
    	) );
    
    }
    add_action( 'init', 'movie_init' );
    
    /**
     * Sets the post updated messages for the <code>movie</code> post type.
     *
     * @param  array $messages Post updated messages.
     * @return array Messages for the <code>movie</code> post type.
     */
    function movie_updated_messages( $messages ) {
    	global $post;
    
    	$permalink = get_permalink( $post );
    
    	$messages['movie'] = array(
    		0  => '', // Unused. Messages start at index 1.
    		/* translators: %s: post permalink */
    		1  => sprintf( __( 'Movie updated. <a target="_blank" href="%s">View Movie</a>', 'twentytwentyone' ), esc_url( $permalink ) ),
    		2  => __( 'Custom field updated.', 'twentytwentyone' ),
    		3  => __( 'Custom field deleted.', 'twentytwentyone' ),
    		4  => __( 'Movie updated.', 'twentytwentyone' ),
    		/* translators: %s: date and time of the revision */
    		5  => isset( $_GET['revision'] ) ? sprintf( __( 'Movie restored to revision from %s', 'twentytwentyone' ), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false,
    		/* translators: %s: post permalink */
    		6  => sprintf( __( 'Movie published. <a href="%s">View Movie</a>', 'twentytwentyone' ), esc_url( $permalink ) ),
    		7  => __( 'Movie saved.', 'twentytwentyone' ),
    		/* translators: %s: post permalink */
    		8  => sprintf( __( 'Movie submitted. <a target="_blank" href="%s">Preview Movie</a>', 'twentytwentyone' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
    		/* translators: 1: Publish box date format, see https://secure.php.net/date 2: Post permalink */
    		9  => sprintf( __( 'Movie scheduled for: <strong>%1$s</strong>. <a target="_blank" href="%2$s">Preview Movie</a>', 'twentytwentyone' ),
    		date_i18n( __( 'M j, Y @ G:i', 'twentytwentyone' ), strtotime( $post->post_date ) ), esc_url( $permalink ) ),
    		/* translators: %s: post permalink */
    		10 => sprintf( __( 'Movie draft updated. <a target="_blank" href="%s">Preview Movie</a>', 'twentytwentyone' ), esc_url( add_query_arg( 'preview', 'true', $permalink ) ) ),
    	);
    
    	return $messages;
    }
    add_filter( 'post_updated_messages', 'movie_updated_messages' );
    
    • This topic was modified 3 years, 2 months ago by Jan Dembowski.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The PHP code/file needs to be included into functions.php or a plugin to actually run. It’s not enough to just create a file. Is post-types your theme? Does functions.php include movie.php?

    Thread Starter tskpbls

    (@tskpbls)

    Hi @jakept , thanks a lot for the very quick response.

    post-types is the folder created under wp-content/themes/twentytwentyone in my case, by the command itself.

    see : https://developer.www.ads-software.com/cli/commands/scaffold/post-type/

    # Generate a 'movie' post type for the 'simple-life' theme
    $ wp scaffold post-type movie --label=Movie --theme=simple-life
    Success: Created '/var/www/example.com/public_html/wp-content/themes/simple-life/post-types/movie.php'.

    So instead of having the code inside the functions.php of a child theme, it creates a specific file for that code, with the path mentioned above.

    Of course, I could create a plugin inside the mu-plugins folder from the movie.php file or copy/paste its code inside functions.php and get rid of it…

    But in that case, what would be the point of having that specific folder created?

    Please consider this as an intermediate (not beginner) question. I know how to use the wpcli/command line, I know about functions.php, child themes and so on… But I would not know what to do now with that movie.php file.

    It’s there for a reason, and I am probably missing something silly to have the CPT shown inside the menu.

    Thanks!

    • This reply was modified 3 years, 2 months ago by tskpbls. Reason: Rephrasing
    Thread Starter tskpbls

    (@tskpbls)

    To make short, here’s my question:

    The code inside movie.php can go inside :
    the functions.php file.

    The movie.php file itself can go :
    under the mu-plugins folder.

    What are the other solutions?

    I think, I was expecting the wpcli command to create the cpt, not just its code.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘CPT from wpcli scaffold not showing in menu.’ is closed to new replies.