Title: using wp function in plugin and getting 500 server error
Last modified: August 20, 2016

---

# using wp function in plugin and getting 500 server error

 *  Resolved [smarie33](https://wordpress.org/support/users/smarie33/)
 * (@smarie33)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/using-wp-function-in-plugin-and-getting-500-server-error/)
 * Hello!
 * I am writing a plugin that creates categories based on an amount specified by
   a form. So I have the form page, it works, you can access it from the dashboard
   menu. When the form is posted it sends to a php page with this code on it:
 *     ```
       //includes this file so that I can use wordpress functions
       include '../../../wp-includes/pluggable.php';
       //comes from the amount specified by the form
       $assignmentamout = $_POST['assignmentamout'];
       //comes from what to call the categories input part of the form
       $namethem = $_POST['namethem'];
   
       //if the input box for naming the assignments is blank, this is the default
       if($namethem == "") $namethem = 'Assignment';
   
       //repeat the createcat categories function for as many times as stated in the form
       for ($i = 1; $i <= $assignmentamout; $i++) {
       	$create = $namethem." ".$i;
       	createcat($create);
       }
       //run this function as many time as the loop says
       function createcat($created){
       	wp_insert_term($created, 'category');
       }
       ```
   
 * If I click ‘submit’ on the form. I immediately get a server error: “HTTP Error
   500 (Internal Server Error): An unexpected condition was encountered while the
   server was attempting to fulfill the request.”
    I tried putting the wp_insert_terms()
   directly into the loop and tried using wp_create_category(). If I do not include
   the pluggable.php I get a ‘function not found’ php error. I ran a lot of echos
   so I know that the script just stops at the wp_insert_terms(). I tried to look
   up server errors, but my server didn’t log any errors. I increased my memory 
   in my php5.ini to 20mb. All my files in my plugin and its folder are permission
   755. Plugin’s that I have installed from elsewhere are working properly. If I
   remove the wp function I get no server error, the page outputs echos I put at
   the end.
 * Maybe I am just building this plugin incorrectly. Any help that anyone could 
   give me would be much appreciated! Or maybe suggest how you would build this 
   part of a plugin.

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Thread Starter [smarie33](https://wordpress.org/support/users/smarie33/)
 * (@smarie33)
 * [14 years, 3 months ago](https://wordpress.org/support/topic/using-wp-function-in-plugin-and-getting-500-server-error/#post-2616232)
 * Maybe you can’t use wordpress functions inside of a plugin with out an add_action
   hook? Can someone verify that? Or maybe I’m missing a php file i need to include?
   Please help.
 *  Thread Starter [smarie33](https://wordpress.org/support/users/smarie33/)
 * (@smarie33)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/using-wp-function-in-plugin-and-getting-500-server-error/#post-2616377)
 * So I looked up my server logs to see what the problem was. Looks like I needed
   to include the taxonomy.php not the pluggable.php. I had to include a lot of 
   different wordpress pages by the end of this plugin. And you can find what php
   page each function is called from in the wordpress documentation at the bottom
   of the page of the function you are reading about. I guess moral of the story
   is: a 500 error = look at your server logs! AAAHHHH noobs…

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘using wp function in plugin and getting 500 server error’ is closed to
new replies.

## Tags

 * [500 server error](https://wordpress.org/support/topic-tag/500-server-error/)
 * [pluggable.php](https://wordpress.org/support/topic-tag/pluggable-php/)

 * In: [Hacks](https://wordpress.org/support/forum/plugins-and-hacks/hacks/)
 * 2 replies
 * 1 participant
 * Last reply from: [smarie33](https://wordpress.org/support/users/smarie33/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/using-wp-function-in-plugin-and-getting-500-server-error/#post-2616377)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
