Tagged: custom post type
- This topic has 6 replies, 3 voices, and was last updated 5 years, 2 months ago by
Steve.
-
AuthorPosts
-
-
November 14, 2016 at 7:38 pm #7536
cosmocanuckMemberHi! I’m using best practices to add a custom post type to a new site I’m developing. But I’ve stumbled right at step one! Sigh… I’ve created and activated a simple plugin, to which I’ve added code based on the example here:
Everything in my one PHP file is below – I can’t figure out what I’ve done wrong… hope someone can enlighten me. Thanks!
Adam
<?php /* Plugin Name: Recipes etc with Piklist Description: Adds custom post types and other features using the Piklist plugin. Version: 1.0 Author: Adam Abrams Author URI: http://www.adamabramsdesign.com Plugin Type: Piklist License: GPL2 */ add_filter('piklist_post_types', 'piklist_demo_post_types'); function piklist_demo_post_types($post_types) { $post_types['recipes'] = array( 'labels' => piklist('post_type_labels', 'Recipes') ,'title' => __('Enter a new Recipe') ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg' ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png' ,'supports' => array( 'title' ,'post-formats' ) ,'public' => true ,'admin_body_class' => array( 'custom-body-class' ) ,'has_archive' => true ,'rewrite' => array( 'slug' => 'recipe' ) ,'capability_type' => 'post' ,'edit_columns' => array( 'title' => __('Recipe') ,'author' => __('Assigned to') ) ,'hide_meta_box' => array( ,'author' ) ,'status' => array( 'new' => array( 'label' => 'New' ,'public' => false ) ,'pending' => array( 'label' => 'Pending Review' ,'public' => false ) ,'demo' => array( 'label' => 'Recipe' ,'public' => true ,'exclude_from_search' => true ,'show_in_admin_all_list' => true ,'show_in_admin_status_list' => true ) ,'lock' => array( 'label' => 'Lock' ,'public' => true ) ) ); return $post_types; } ?> -
November 16, 2016 at 3:30 pm #7547
cosmocanuckMemberContinuing to troubleshoot, I tried simply pasting in the untouched sample code above. But now I get the following error when trying to activate it:
Plugin could not be activated because it triggered a fatal error.
Parse error: syntax error, unexpected ‘,’, expecting ‘)’ in /nfs/c01/h08/mnt/7211/domains/hons.ca/html/wordpress/wp-content/plugins/piklist-hons/piklist-hons.php on line 39Hmmmm? Here is my current contents of the php file (with line 39 indicated by a comment):
<?php /* Plugin Name: HON'S Piklist Description: Adds custom post types and other features using the Piklist plugin. Version: 1.0 Author: Adam Abrams Author URI: http://www.adamabramsdesign.com Plugin Type: Piklist */ add_filter('piklist_post_types', 'piklist_demo_post_types'); function piklist_demo_post_types($post_types) { $post_types['piklist_demo'] = array( 'labels' => piklist('post_type_labels', 'Piklist Demo') ,'title' => __('Enter a new Demo Title') ,'menu_icon' => piklist('url', 'piklist') . '/parts/img/piklist-menu-icon.svg' ,'page_icon' => piklist('url', 'piklist') . '/parts/img/piklist-page-icon-32.png' ,'supports' => array( 'title' ,'post-formats' ) ,'public' => true ,'admin_body_class' => array( 'custom-body-class' ) ,'has_archive' => true ,'rewrite' => array( 'slug' => 'piklist-demo' ) ,'capability_type' => 'post' ,'edit_columns' => array( 'title' => __('Demo') ,'author' => __('Assigned to') ) ,'hide_meta_box' => array( ,'author' /* THIS IS LINE 39 */ ) ,'status' => array( 'new' => array( 'label' => 'New' ,'public' => false ) ,'pending' => array( 'label' => 'Pending Review' ,'public' => false ) ,'demo' => array( 'label' => 'Demo' ,'public' => true ,'exclude_from_search' => true ,'show_in_admin_all_list' => true ,'show_in_admin_status_list' => true ) ,'lock' => array( 'label' => 'Lock' ,'public' => true ) ) ); return $post_types; } -
November 16, 2016 at 4:59 pm #7550
JasonKeymasterYou have an extra comma preceding ‘author’ on line 39. Change
,'author'to'author'. 🙂 -
November 16, 2016 at 6:36 pm #7552
cosmocanuckMemberAha. It works! Thanks!
But y’know what….
THAT COMMA IS IN THE DEMO CODE.
argh
Someone ought to fix that… ;^)
Thank you!
adam -
November 16, 2016 at 6:52 pm #7553
JasonKeymasterHey Adam!
Glad that fixed it! Sorry for the bug in the demo code, I’ll get that fixed immediately! Thanks for pointing that out!
-
November 16, 2016 at 6:59 pm #7554
cosmocanuckMemberGlad to help the site be even better and more accurate!
All the best!
-
November 16, 2016 at 11:00 pm #7555
SteveKeymasterFixed! Thanks, guys.
-
-
AuthorPosts
- The topic ‘Creating a CPT in a plugin – what am I doing wrong?’ is closed to new replies.