• 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)
  • 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

    (@gombroo)

    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!

    None of the parent theme files should be edited at all. Everything goes in child theme.

    get_stylesheet_directory()
    https://codex.www.ads-software.com/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

    (@gombroo)

    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.

    but still I got some syntax error.

    “some” or “same” ? and what the error message is saying ?

    Theme Author Sami Keijonen

    (@samikeijonen)

    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.

    https://www.ads-software.com/plugins/pluginception/

    Or if you want to learn more about how to make a plugin, I’d start with this.

    https://codex.www.ads-software.com/Writing_a_Plugin

    Thread Starter gombroo

    (@gombroo)

    @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' );
    ?>

    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

    (@samikeijonen)

    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.