0

This is how I created the custom post type

function wp_custom_post_type_listing()
{

    $labels = array(
        'name'               => _x('Listing', 'post type general name', 'wpprolister'),
        'singular_name'      => _x('Listing', 'post type singular name' ,'wpprolister'),
        'add_new'            => _x('Add new listing', 'l', 'wpprolister'),
        'all_item'           => __('All Listing', 'wpprolister'),
        'add_new_item'       => __('Add new listing', 'wpprolister'),
        'edit_item'          => __('Edit Listing', 'wpprolister'),
        'new_item'           => __('New Listing', 'wpprolister'),
        'view_item'          => __('View Listing', 'wpprolister'),
        'search_item'        => __('Search Listing', 'wpprolister'),
        'not_found'          => __('No Listing found', 'wpprolister'),
        'not_found_in_trash' => __('No listings found in trash', 'wpprolister'),
        'parent_item_colon'  => __('Parent Listing', 'wpprolister'),
    );

    $args_listing = array(
        'labels'              => $labels,
        'public'              => true,
        'has_archive'         => true,
        'publicly_queryable'  => true,
        'query_var'           => true,
        'rewrite'             => true,
        'menu_icon'           => plugins_url( 'images/list.png', __FILE__ ),
        'capability_type'     => 'listing',
        'capabilities'        => array(
            'edit_post'              => 'edit_listing',
            'read_post'              => 'read_listing',
            'delete_post'            => 'delete_listing',
            'edit_posts'             => 'edit_listings',
            'edit_others_posts'      => 'edit_others_listings',
            'publish_posts'          => 'publish_listings',
            'read_private_posts'     => 'read_private_listings',
            'create_posts'           => 'edit_listings',
            'delete_posts'           => 'delete_listings',
            'delete_published_posts' => 'delete_published_listing',
            'delete_others_posts'    => 'delete_others_listings',
            'edit_published_posts'   => 'edit_published_listings',
        ),
        'hierarchical'        => false,
        'map_meta_cap'        => false,
        'supports'            => array(
            'title',
            'editor',
            'expert',
            'thumbnail',
            'comments',
            'page-attributes',
        ),
        'taxonomies'          => array('listing_categories', 'locations', 'amenities', 'post_tag'),
        'menu_position'       => 2,
        'exclude_from_search' => false,
    );
    register_post_type('l', $args_listing);
}

But the post attribute to select a post template does not show up. I have added in the template page-fullwidth.php

<?php if ( ! defined( 'ABSPATH' ) ) exit;
/*
Template Name: Full Width
Template Post Type: post, page , l
*/
get_header();
get_template_part( '/wpprolister-templates/content', 'titlebar'); ?>

I already have a template assigned for the custom post type single-l.php but I want an additional post template

1 Answer 1

0

If I understand your question correctly, you need option to select page template in a custom post type. In order to do that you have to take a different approach.

In your page-fullwidth.php add template name using the following code:

/*
Template Name: Full-width layout
Template Post Type: l
*/
get_header();

In theory, the default template should fall back to single-l.php but if not please do let me know.

Also to clear out the misunderstanding on page_attributes argument, it only provides option for selecting menu order and selecting a parent if hierarchical is set to true.

9
  • Yes I have added that in the template but still does not work
    – user145078
    Commented Jul 20, 2019 at 15:14
  • Also remove the if condition from the first line please. Commented Jul 20, 2019 at 16:09
  • I don't think that's gonna make a difference but I tried that. Still, it does not work
    – user145078
    Commented Jul 20, 2019 at 18:28
  • Are you able to see the custom template in posts and pages? Commented Jul 21, 2019 at 5:28
  • there is no option to select anything new. single-l.php is the only template..which becomes the template for custom posts listing(l)
    – user145078
    Commented Jul 21, 2019 at 9:18

Your Answer

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