Closed MikeiLL closed 4 years ago
Made a little headway!
If I replace the contents of public function load_cpts()
with
register_extended_post_type( 'article' );
the article
CPT is created.
And when I use this from extended-cpts docs:
I get "articles" CPT:
register_extended_post_type( 'story', [
# Add the post type to the site's main RSS feed:
'show_in_feed' => true,
# Show all posts on the post type archive:
'archive' => [
'nopaging' => true,
],
# Add the post type to the 'Recently Published' section of the dashboard:
'dashboard_activity' => true,
# Add some custom columns to the admin screen:
'admin_cols' => [
'story_featured_image' => [
'title' => 'Illustration',
'featured_image' => 'thumbnail'
],
'story_published' => [
'title_icon' => 'dashicons-calendar-alt',
'meta_key' => 'published_date',
'date_format' => 'd/m/Y'
],
'story_genre' => [
'taxonomy' => 'genre'
],
],
# Add some dropdown filters to the admin screen:
'admin_filters' => [
'story_genre' => [
'taxonomy' => 'genre'
],
'story_rating' => [
'meta_key' => 'star_rating',
],
],
], [
# Override the base names used for labels:
'singular' => 'Story',
'plural' => 'Stories',
'slug' => 'stories',
] );
register_extended_taxonomy( 'genre', 'story', [
# Use radio buttons in the meta box for this taxonomy on the post editing screen:
'meta_box' => 'radio',
# Add a custom column to the admin screen:
'admin_cols' => [
'updated' => [
'title_cb' => function() {
return '<em>Last</em> Updated';
},
'meta_key' => 'updated_date',
'date_format' => 'd/m/Y'
],
],
] );
If you'd like me update current snippet and submit a PR, please let me know.
The line you refer and file is https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/plugin-name/internals/PostTypes.php#L113 What are the differences with your code and the one in the boilerplate except the different custom post type?
This is what the generator produced (if that's what you are referring to), which was not working:
/**
* Load CPT and Taxonomies on WordPress
*
* @since 1.0.0
*
* @return void
*/
public function load_cpts() {
// Create Custom Post Type https://github.com/johnbillion/extended-cpts/wiki
$tax = register_extended_post_type(
'demo',
array(
// Show all posts on the post type archive:
'archive' => array(
'nopaging' => true,
),
'slug' => 'demo',
'show_in_rest' => true,
'dashboard_activity' => true,
'capability_type' => array( 'demo', 'demoes' ),
// Add some custom columns to the admin screen
'admin_cols' => array(
'featured_image' => array(
'title' => 'Featured Image',
'featured_image' => 'thumbnail',
),
'title',
'genre' => array(
'taxonomy' => 'demo-section',
),
'custom_field' => array(
'title' => 'By Lib',
'meta_key' => '_demo_' . MMC_TEXTDOMAIN . '_text',
'cap' => 'manage_options',
),
'date' => array(
'title' => 'Date',
'default' => 'ASC',
),
),
// Add a dropdown filter to the admin screen:
'admin_filters' => array(
'genre' => array(
'taxonomy' => 'demo-section',
),
),
),
array(
// Override the base names used for labels:
'singular' => __( 'Demo', MMC_TEXTDOMAIN ),
'plural' => __( 'Demos', MMC_TEXTDOMAIN ),
)
);
$tax->add_taxonomy(
'demo-section',
array(
'hierarchical' => false,
'show_ui' => false,
)
);
// Create Custom Taxonomy https://github.com/johnbillion/extended-taxos
register_extended_taxonomy(
'demo-section',
'demo',
array(
// Use radio buttons in the meta box for this taxonomy on the post editing screen:
'meta_box' => 'radio',
// Show this taxonomy in the 'At a Glance' dashboard widget:
'dashboard_glance' => true,
// Add a custom column to the admin screen:
'admin_cols' => array(
'featured_image' => array(
'title' => 'Featured Image',
'featured_image' => 'thumbnail',
),
),
'slug' => 'demo-cat',
'show_in_rest' => true,
'capabilities' => array(
'manage_terms' => 'manage_demoes',
'edit_terms' => 'manage_demoes',
'delete_terms' => 'manage_demoes',
'assign_terms' => 'read_demo',
),
),
array(
// Override the base names used for labels:
'singular' => __( 'Demo Category', MMC_TEXTDOMAIN ),
'plural' => __( 'Demo Categories', MMC_TEXTDOMAIN ),
)
);
}
Looks the same. I wonder if the included snippet shouldn't be the minimal example. Not sure. By the way this is a great set of tools. Thank you and I'm glad I found it.
In my testing the demo
custom post type is generated, so if the only difference with your code is the post type it is something on your instance.
Thanks for the boilerplate's appreciation :-D
I'm facing a similar issue and have noticed by accessing via url: wp-admin/edit.php?post_type=demo
WordPress states: You need a higher level of permission. Sorry, you are not allowed to edit posts in this post type.
So it seems like the CPT is being created. Just an issue with permissions?
Running WP 5.9 with PHP 8.0 and also tried WP 5.7 with PHP 8.0
@liamb13 my guess is that the code in https://github.com/WPBP/WordPress-Plugin-Boilerplate-Powered/blob/master/plugin-name/backend/ActDeact.php wasn't executed that assign the permission for the new post type.
Describe the bug I'm not seeing the "demo" PostType
To Reproduce Steps to reproduce the behavior:
Thank you and sorry if I'm missing something obvious.