Title: Custom post types problem and &quot;fatal error: require_once() &quot; message
Last modified: August 21, 2016

---

# Custom post types problem and "fatal error: require_once() " message

 *  [gombroo](https://wordpress.org/support/users/gombroo/)
 * (@gombroo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/)
 * Hello,
 * I’ve registered some custom post types in my child theme. They are included in
   the directory: libs/posttypes.php and looks like this:
 *     ```
       <?php
       add_action('init', 'mamepro_init_posttypes');
       function mamepro_init_posttypes() {
   
       /* Register Announcements  */
               $announcements_args = array(
                   'labels' => array(
                       'name' => 'Ogłoszenia',
                       'singular_name' => 'Ogloszenie',
                       'all_items' => 'Wszystkie ogłoszenia',
                       'add_new' => 'Dodaj nowe ogłoszenie',
                       'add_new_item' => 'Dodaj nowe ogłoszenie',
                       'edit_item' => 'Edytuj ogłoszenie',
                       'new_item' => 'Nowe ogłoszenie',
                       'view_item' => 'Zobacz ogłoszenie',
                       'search_items' => 'Szukaj w ogłoszeniach',
                       'not_found' =>  'Nie znaleziono żadnych ogłoszeń',
                       'not_found_in_trash' => 'Nie znaleziono żadnych ogłoszeń w koszu',
                       'parent_item_colon' => ''
                   ),
                   'public' => true,
                   'publicly_queryable' => true,
                   'show_ui' => true,
                   'query_var' => true,
                   'rewrite' => true,
                   'capability_type' => 'post',
                   'hierarchical' => false,
                   'menu_position' => 5,
                   'supports' => array(
                       'title','editor','author','thumbnail','excerpt','comments','custom-fields'
                   ),
                   'has_archive' => true
               );
   
               register_post_type('announcements', $announcements_args);
       }
       ?>
       ```
   
 * I added a function to funcions.php file located in my child theme directory to
   make it work:
 * require_once MAMEPRO_THEME_DIR.’libs/posttypes.php’;
 * But as a result I got an error message:
 * `Warning: require_once(/home/marszand/domains/mamepro.org/public_html/wp-content/
   themes/path/libs/posttypes.php) [function.require-once]: failed to open stream:
   No such file or directory in /home/marszand/domains/mamepro.org/public_html/wp-
   content/themes/mamepro/functions.php on line 11`
 * Fatal error: require_once() [function.require]: Failed opening required ‘/home/
   marszand/domains/mamepro.org/public_html/wp-content/themes/path/libs/posttypes.
   php’ (include_path=’.:/usr/local/php/p53/lib/php’) in /home/marszand/domains/
   mamepro.org/public_html/wp-content/themes/mamepro/functions.php on line 11
 * I wonder why wordpress can’t find posttypes.php and funcions.php files. If you
   can help me I’d be grateful!
 * Thanks in advance!

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

 *  [paulwpxp](https://wordpress.org/support/users/paulwp/)
 * (@paulwp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882585)
 * Reading from the error message, this `MAMEPRO_THEME_DIR` doesn’t point to your
   child theme’s directory(folder). It’s pointing to parent theme’s directory and
   couldn’t find such file.
 *  Thread Starter [gombroo](https://wordpress.org/support/users/gombroo/)
 * (@gombroo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882612)
 * Thanks! I could noticed it so far.
 * The problem is: how can I change it? Which parent file I should edit and which
   function should I use?
 * I’m a complete beginner in php, so any advice will be helpful!
 *  [paulwpxp](https://wordpress.org/support/users/paulwp/)
 * (@paulwp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882626)
 * None of the parent theme files should be edited at all. Everything goes in child
   theme.
 * get_stylesheet_directory()
    [http://codex.wordpress.org/Function_Reference/get_stylesheet_directory](http://codex.wordpress.org/Function_Reference/get_stylesheet_directory)
 *     ```
       require( get_stylesheet_directory() . '/libs/posttypes.php' );
       ```
   
 * That is in your child theme’s setup function, and you have `posttypes.php` inside
   child folder like this `mamepro/libs/posttypes.php`
 *  Thread Starter [gombroo](https://wordpress.org/support/users/gombroo/)
 * (@gombroo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882738)
 * My child-theme functions.php which causes this error looks like this:
 *     ```
       if(!defined('MAMEPRO_THEME_DIR')) {
       define('MAMEPRO_THEME_DIR',get_theme_root().'/'.get_template().'/');
       }
   
       if(!defined('MAMEPRO_THEME_URL')) {
       define('MAMEPRO_THEME_URL',WP_CONTENT_URL.'/themes/'.get_template().'/');
       }
       require_once MAMEPRO_THEME_DIR.'libs/posttypes.php';
       ```
   
 * I tried to replace this:
 * > require_once MAMEPRO_THEME_DIR.’libs/posttypes.php’;
 * with this:
 * > require( get_stylesheet_directory() . ‘/libs/posttypes.php’ );
 * but still I got some syntax error.
 *  [paulwpxp](https://wordpress.org/support/users/paulwp/)
 * (@paulwp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882747)
 * > but still I got some syntax error.
 * “some” or “same” ? and what the error message is saying ?
 *  Theme Author [Sami Keijonen](https://wordpress.org/support/users/samikeijonen/)
 * (@samikeijonen)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882751)
 * Before you go on, you should not register your custom post type in a theme. It
   belongs in a custom plugin because you’re not gonna use Path theme forever.
 * You can make your custom plugin with this.
 * [http://wordpress.org/plugins/pluginception/](http://wordpress.org/plugins/pluginception/)
 * Or if you want to learn more about how to make a plugin, I’d start with this.
 * [https://codex.wordpress.org/Writing_a_Plugin](https://codex.wordpress.org/Writing_a_Plugin)
 *  Thread Starter [gombroo](https://wordpress.org/support/users/gombroo/)
 * (@gombroo)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882831)
 * @paulwpxp this error says:
 * > Parse error: syntax error, unexpected ‘}’ in /home/marszand/domains/mamepro.
   > org/public_html/wp-content/themes/mamepro/libs/posttypes.php on line 114
 * Nothing changes when I try to remove or put this bracket in another place.
 * The whole posttypes.php looks like this:
 *     ```
       <?php
       if(!defined('MAMEPRO_THEME_DIR')) {	define('MAMEPRO_THEME_DIR',get_theme_root().'/'.get_template().'/');
       }
       if(!defined('MAMEPRO_THEME_URL')) {
       	define('MAMEPRO_THEME_URL',WP_CONTENT_URL.'/themes/'.get_template().'/');
       }
       require( get_stylesheet_directory() . '/libs/posttypes.php' );
       ?>
       ```
   
 *  [paulwpxp](https://wordpress.org/support/users/paulwp/)
 * (@paulwp)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882832)
 * Now the error is not about pointing to the wrong folder/file. It’s now the syntax
   error in `posttypes.php`. So please check it there.
 * The code you posted above should NOT be from `posttypes.php`, it should be from`
   functions.php`. Also, since now we are using `get_stylesheet_directory()` to 
   get to that file, so there is no need to define those constants, unless you need
   to call them somewhere else.
 *  Theme Author [Sami Keijonen](https://wordpress.org/support/users/samikeijonen/)
 * (@samikeijonen)
 * [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882834)
 * Register Code should be in a plugin.

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

The topic ‘Custom post types problem and "fatal error: require_once() " message’
is closed to new replies.

 * ![](https://i0.wp.com/themes.svn.wordpress.org/path/0.2.1.2/screenshot.png)
 * Path
 * [Support Threads](https://wordpress.org/support/theme/path/)
 * [Active Topics](https://wordpress.org/support/theme/path/active/)
 * [Unresolved Topics](https://wordpress.org/support/theme/path/unresolved/)
 * [Reviews](https://wordpress.org/support/theme/path/reviews/)

## Tags

 * [custom post type](https://wordpress.org/support/topic-tag/custom-post-type/)
 * [functions](https://wordpress.org/support/topic-tag/functions/)
 * [path theme](https://wordpress.org/support/topic-tag/path-theme/)

 * 9 replies
 * 3 participants
 * Last reply from: [Sami Keijonen](https://wordpress.org/support/users/samikeijonen/)
 * Last activity: [12 years, 11 months ago](https://wordpress.org/support/topic/custom-post-types-problem-2/#post-3882834)
 * Status: not resolved