1

I created a CPT with slug plist via cutom plugin I made.

In my local host the archive work but in live server it return blank page.

Here is the 'include' archive page code

/**
 * Add Price List archive template
 * @since    1.0.0
*/
add_filter( 'archive_template', 'get_plist_archive_template' ) ;
function get_plist_archive_template( $archive_template ) {
     global $post;

     if ( is_post_type_archive ( 'plist' ) ) {
          $archive_template = dirname( __FILE__ ) . '\partials\archive-plist.php';
     }
     return $archive_template;
}

Link: http://cratetimer.com/plist/

Also this may help:

/**
 * Register Custom Post Type Price List
 * @since    1.0.0
*/
if ( ! function_exists('price_item_post_type') ) {
    add_action( 'init', 'price_item_post_type', 0 );
    // Register Custom Post Type
    function price_item_post_type() {

        $labels = array(
            'name'                  => _x( 'Price Lists', 'Post Type General Name', 'plist' ),
            'singular_name'         => _x( 'Price List', 'Post Type Singular Name', 'plist' ),
            'menu_name'             => __( 'Price List', 'plist' ),
            'name_admin_bar'        => __( 'Price List', 'plist' ),
            'archives'              => __( 'Price List Archives', 'plist' ),
            'attributes'            => __( 'Price List Attributes', 'plist' ),
            'parent_item_colon'     => __( 'Parent Price List:', 'plist' ),
            'all_items'             => __( 'All Price Lists', 'plist' ),
            'add_new_item'          => __( 'Add New Price List', 'plist' ),
            'add_new'               => __( 'Add New', 'plist' ),
            'new_item'              => __( 'New Price List', 'plist' ),
            'edit_item'             => __( 'Edit Price List', 'plist' ),
            'update_item'           => __( 'Update Price List', 'plist' ),
            'view_item'             => __( 'View Price List', 'plist' ),
            'view_items'            => __( 'View Price Lists', 'plist' ),
            'search_items'          => __( 'Search Price List', 'plist' ),
            'not_found'             => __( 'Not found', 'plist' ),
            'not_found_in_trash'    => __( 'Not found in Trash', 'plist' ),
            'featured_image'        => __( 'Featured Image', 'plist' ),
            'set_featured_image'    => __( 'Set featured image', 'plist' ),
            'remove_featured_image' => __( 'Remove featured image', 'plist' ),
            'use_featured_image'    => __( 'Use as featured image', 'plist' ),
            'insert_into_item'      => __( 'Insert into Price List', 'plist' ),
            'uploaded_to_this_item' => __( 'Uploaded to this Price List', 'plist' ),
            'items_list'            => __( 'Price Lists', 'plist' ),
            'items_list_navigation' => __( 'Price Lists navigation', 'plist' ),
            'filter_items_list'     => __( 'Filter Price Lists', 'plist' ),
        );
        $args = array(
            'label'                 => __( 'Price List', 'plist' ),
            'description'           => __( 'Price list item for market', 'plist' ),
            'labels'                => $labels,
            'supports'              => array( ),
            'hierarchical'          => false,
            'public'                => true,
            'show_ui'               => true,
            'show_in_menu'          => true,
            'menu_position'         => 20,
            'menu_icon'             => 'dashicons-tag',
            'show_in_admin_bar'     => true,
            'show_in_nav_menus'     => true,
            'can_export'            => true,
            'has_archive'           => true,        
            'exclude_from_search'   => true,
            'publicly_queryable'    => true,
            'capability_type'       => 'page',
        );
        register_post_type( 'plist', $args );

    }

}

I tried flush_rewrite_rules() and it didn't work.

7
  • Please instead of vote down my question, tell me what is wrong with it maybe I can improve it.
    – Yamona
    Commented Oct 29, 2017 at 1:34
  • your archive template contains an archive template filter? The filter is applied before the template is loaded, that can’t possibly work.
    – Milo
    Commented Oct 29, 2017 at 1:54
  • If you mean get_plist_archive_template. This run outside the archive template archive-plist.php.
    – Yamona
    Commented Oct 29, 2017 at 1:59
  • How I can correct my code?
    – Yamona
    Commented Oct 29, 2017 at 3:49
  • 1
    In that case you'll have to debug get_plist_archive_template. Print $archive_template and see if it is taking roper value. Commented Oct 29, 2017 at 11:51

2 Answers 2

0

You have to tell WP that archive.php should apply to your custom post type as well as it's other defaults. You can use pre_get_posts filter to do this, be sure to research this well before using it as there is a right and wrong way to use this filter.

For example, try:

function add_custom_post_type_to_archiving( $query ) {
    $query->set( 'post_type', array(
     'post', 'custom_post_type_name1','custom_post_type_name2'
        ));
    return $query;
}
add_filter( 'pre_get_posts', 'add_custom_post_type_to_archiving' );
0

Since it is working on your local machine and not on the server, I suspect that it is environment related. This causes me to suspect:

$archive_template = dirname( __FILE__ ) . '\partials\archive-plist.php';

If you are running this on a standard LAMP stack, it is likely that you should be using forward slashes (/) instead of backslashes (\).

Also, there is a chance that the dirname() call is returning a path with a slash at the end, which would mean that the path has a double slash in it ( likely /\).

I suggest trying to change the direction of your slashes, and then changing dirname() to plugin_dir_path(). You'll notice that plugin_dir_path() utilizes a function named trailingslashit() which appends a trailing slash if there isn't one already. This means that you should remove the first slash in your path.

All together, it would look like this:

$archive_template = plugin_dir_path( __FILE__ ) . 'partials/archive-plist.php';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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