1

I need to create a plugin in wordpress 3.9 for custom post types.When i activate the plugin, am getting an internal server error 500. Also plugins are not listing in admin dashboard. Here is my code:

<?php  
/**
* Plugin Name: Name Of The Plugin
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/

add_action('init', 'register_wp_questions');

$labels = array(
'name' => __( 'Questions', 'wp_question' ),
'singular_name' => __( 'Question', 'wp_question' ),
'add_new' => __( 'Add New', 'wp_question' ),
'add_new_item' => __( 'Add New Question', 'wp_question' ),
'edit_item' => __( 'Edit Questions', 'wp_question' ),
'new_item' => __( 'New Question', 'wp_question' ),
'view_item' => __( 'View Question', 'wp_question' ),
'search_items' => __( 'Search Questions', 'wp_question' ),
'not_found' => __( 'No Questions found', 'wp_question' ),
'not_found_in_trash' => __( 'No Questions found in Trash','wp_question' ),
'parent_item_colon' => __( 'Parent Question:', 'wp_question'),
'menu_name' => __( 'Questions', 'wp_question' )
);


$args = array(
'labels' => $labels,
'hierarchical' => true,
'description'  => __( 'Questions and Answers', 'wp_question' ),
'supports'     => array( 'title', 'editor', 'comments' ),
'public'       => true,
'show_ui'       => true,
'show_in_menu'       => true,
'show_in_nav_menus'       => true,
'publicly_queryable'       => true,
'exclude_from_search'       => true,
'has_archive'       => true,
'query_var'       => true,
'can_export'       => true,
'rewrite'       => true,
'capability_type'       => true
);

register_post_type ('wp_question', $args);

?>

Please help. How can i figure out the error?

Thanks

  • Check the first array, the last item in it has comma, it shouldnt be there na? – vaibhav Apr 29 '14 at 6:11
  • yeah i have removed that, but still not working.Is the code format is correct? – user47126 Apr 29 '14 at 6:13
  • Actually when i activate the plugin it will not load even the admin dashboard. – user47126 Apr 29 '14 at 6:15
  • Can you say the exact error?.. – vaibhav Apr 29 '14 at 6:18
1

What does add_action('init', 'register_wp_questions'); do in your plugin. At this stage this is your problem. You are hooking a function to init that does not exist, thus giving you an error.

I suppose that you need to register and hook your CPT to the init hook. You should actually put all that code in a function and then add it to the init hook. Your code should be

<?php  
/**
* Plugin Name: Name Of The Plugin
* Plugin URI: http://URI_Of_Page_Describing_Plugin_and_Updates
* Description: A brief description of the Plugin.
* Version: The Plugin's Version Number, e.g.: 1.0
* Author: Name Of The Plugin Author
* Author URI: http://URI_Of_The_Plugin_Author
* License: A "Slug" license name e.g. GPL2
*/

add_action('init', 'register_wp_questions');

function register_wp_questions() {
$labels = array(
'name' => __( 'Questions', 'wp_question' ),
'singular_name' => __( 'Question', 'wp_question' ),
'add_new' => __( 'Add New', 'wp_question' ),
'add_new_item' => __( 'Add New Question', 'wp_question' ),
'edit_item' => __( 'Edit Questions', 'wp_question' ),
'new_item' => __( 'New Question', 'wp_question' ),
'view_item' => __( 'View Question', 'wp_question' ),
'search_items' => __( 'Search Questions', 'wp_question' ),
'not_found' => __( 'No Questions found', 'wp_question' ),
'not_found_in_trash' => __( 'No Questions found in Trash','wp_question' ),
'parent_item_colon' => __( 'Parent Question:', 'wp_question'),
'menu_name' => __( 'Questions', 'wp_question' )
);


$args = array(
'labels' => $labels,
'hierarchical' => true,
'description'  => __( 'Questions and Answers', 'wp_question' ),
'supports'     => array( 'title', 'editor', 'comments' ),
'public'       => true,
'show_ui'       => true,
'show_in_menu'       => true,
'show_in_nav_menus'       => true,
'publicly_queryable'       => true,
'exclude_from_search'       => true,
'has_archive'       => true,
'query_var'       => true,
'can_export'       => true,
'rewrite'       => true,
'capability_type'       => true
);

register_post_type ('wp_question', $args);

}

?>
  • oh yeah! i forgot to place the function in my code. It is my mistake..anyways thanks for the help :) – user47126 Apr 29 '14 at 6:37
  • My pleasure. Glad I could help – Pieter Goosen Apr 29 '14 at 6:39
  • One more issue is there, i cant find the option for adding custom post type in Admin Dashboard.But i could activate the plugin. – user47126 Apr 29 '14 at 6:49
  • This doesn't seem to be related to your code, as everything checks out from what I can see. Your CPT should be below comments. This might be a problem with capabilities set. Check out the codex on register_post_type – Pieter Goosen Apr 29 '14 at 7:06
  • i got it, i have to give the 'capability_type' field to 'post' instead of true.Thanks @Pieter Goosen :) – user47126 Apr 29 '14 at 9:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.