jjgrainger/wp-custom-post-type-class

Using CPT

mmjaeger opened this issue · 3 comments

Hello
Could you please tell me how I could set up the following code using your class:

register_post_type( 'ta_case',
array(
'labels' => array(
'name' => __( 'Cases', 'ta' ),
'singular_name' => __( 'Case', 'ta' ),
'add_new_item' => __( 'Add new case', 'ta' ),
),
'has_archive' => true,
'hierarchical' => false,
'menu_icon' => 'dashicons-book-alt',
'menu_position' => 50,
'public' => true,
'rewrite' => array( 'slug' => 'case', 'with_front' => false ),
'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' )
)
);

Thanks

The following is untested but should work

// the post types names, labels and slug
$names = array(
    'post_type_name' => 'ta_cases',
    'singular' => 'Case',
    'plural' => 'Cases',
    'slug' => 'case'
);

// post type options
$options = array(
    'has_archive' => true,
    'hierarchical' => false,
    'menu_position' => 50,
    'public' => true,
    'rewrite' => array( 'with_front' => false ),
    'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attributes', 'genesis-seo', 'genesis-cpt-archives-settings' )
);

// create the post type with the class and variables
$cases = new CPT($names, $options);

// set the post types menu icon
$cases->menu_icon('dashicons-book-alt');

// set the textdomain
$cases->set_textdomain('ta');

Thanks Joe - really appreciate your input.

Please allow me another quick question - in regards to showing the custom
field columns in the admin - is there a way to define some excerpt using
the CPT class - I have rather long text fields and I don't want to show the
full content.

Thanks again.

On Mon, Apr 27, 2015 at 3:05 PM, Joe Grainger notifications@github.com
wrote:

The following should work, but is untested

// the post types names, labels and slug$names = array( 'post_type_name' => 'ta_cases', 'singular' => 'Case', 'plural' => 'Cases', 'slug' => 'case');// post type options$options = array( 'has_archive' => true, 'hierarchical' => false, 'menu_position' => 50, 'public' => true, 'rewrite' => array( 'with_front' => false ), 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'trackbacks', 'custom-fields', 'revisions', 'page-attribute
s', 'genesis-seo', 'genesis-cpt-archives-settings' ));// create the post type with the class and variables$cases = new CPT($names, $options);// set the post types menu icon$cases->menu_icon('dashicons-book-alt');// set the textdomain$cases->set_textdomain('ta');


Reply to this email directly or view it on GitHub
#31 (comment)
.

Marco M. Jaeger
http://net4visions.com

The Class itself doesn't have this kind of functionality and it doesn't really need to.

From what I understand what you're asking for could be achieved with a PHP function like substr (see php.net).

You'll have to do some research to find a solution best suited to your needs.