Im trying to understand how to get the custom field incr_number into admin columns. However im failing to understand and im googling but not finding a direct answer.
It cant be that hard surly?
<?php
/*-----------------------------------------------------------------------------------*/
/* WooThemes supportpress Custom Post Types Init */
/*-----------------------------------------------------------------------------------*/
function woo_supportpress_post_types_init() {
add_option('tickets_slug', 'tickets');
register_post_type( 'ticket',
array(
'label' => __( 'Ticket', 'woothemes' ),
'labels' => array(
'name' => __( 'Tickets', 'woothemes' ),
'singular_name' => __( 'Ticket', 'woothemes' ),
'all_items' => __( 'All Tickets', 'woothemes' ),
'add_new' => __( 'Add New', 'woothemes' ),
'add_new_item' => __( 'Add New Ticket', 'woothemes' ),
'edit' => __( 'Edit', 'woothemes' ),
'edit_item' => __( 'Edit Ticket', 'woothemes' ),
'new_item' => __( 'New Ticket', 'woothemes' ),
'view' => __( 'View Tickets', 'woothemes' ),
'view_item' => __( 'View Ticket', 'woothemes' ),
'search_items' => __( 'Search Tickets', 'woothemes' ),
'not_found' => __( 'No tickets found', 'woothemes' ),
'not_found_in_trash' => __( 'No tickets found in trash', 'woothemes' ),
'parent' => __( 'Parent Tickets', 'woothemes' ),
),
'description' => __( 'This is where you can create new tickets for your site. Tickets can also be created from the front-end.', 'woothemes' ),
'public' => true,
'menu_position' => 4,
'show_ui' => true,
'capability_type' => 'post',
'publicly_queryable' => true,
'exclude_from_search' => true,
'hierarchical' => false,
'rewrite' => array( 'slug' => get_option('tickets_slug'), 'with_front' => false ),
'query_var' => true,
'has_archive' => 'tickets',
'supports' => array( 'title', 'editor', 'custom-fields', 'author', 'comments' ),
)
);
register_taxonomy( 'ticket_status',
array('ticket'),
array(
'hierarchical' => true,
'labels' => array(
'name' => __( 'Ticket Statuses', 'woothemes'),
'singular_name' => __( 'Ticket Status', 'woothemes'),
'search_items' => __( 'Search Ticket Statuses', 'woothemes'),
'all_items' => __( 'All Ticket Statuses', 'woothemes'),
'parent_item' => __( 'Parent Ticket Status', 'woothemes'),
'parent_item_colon' => __( 'Parent Ticket Status:', 'woothemes'),
'edit_item' => __( 'Edit Ticket Status', 'woothemes'),
'update_item' => __( 'Update Ticket Status', 'woothemes'),
'add_new_item' => __( 'Add New Ticket Status', 'woothemes'),
'new_item_name' => __( 'New Ticket Status', 'woothemes')
),
'public' => true,
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'ticket-status', 'with_front' => false ),
)
);
register_taxonomy( 'ticket_priority',
array('ticket'),
array(
'hierarchical' => true,
'labels' => array(
'name' => __( 'Ticket Priorities', 'woothemes'),
'singular_name' => __( 'Ticket Priority', 'woothemes'),
'search_items' => __( 'Search Ticket Priorities', 'woothemes'),
'all_items' => __( 'All Ticket Priorities', 'woothemes'),
'parent_item' => __( 'Parent Ticket Priority', 'woothemes'),
'parent_item_colon' => __( 'Parent Ticket Priority:', 'woothemes'),
'edit_item' => __( 'Edit Ticket Priority', 'woothemes'),
'update_item' => __( 'Update Ticket Priority', 'woothemes'),
'add_new_item' => __( 'Add New Ticket Priority', 'woothemes'),
'new_item_name' => __( 'New Ticket Priority', 'woothemes')
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'ticket-priority', 'with_front' => false ),
)
);
register_taxonomy( 'ticket_type',
array('ticket'),
array(
'hierarchical' => true,
'labels' => array(
'name' => __( 'Ticket Types', 'woothemes'),
'singular_name' => __( 'Ticket Type', 'woothemes'),
'search_items' => __( 'Search Ticket Types', 'woothemes'),
'all_items' => __( 'All Ticket Types', 'woothemes'),
'parent_item' => __( 'Parent Ticket Type', 'woothemes'),
'parent_item_colon' => __( 'Parent Ticket Type:', 'woothemes'),
'edit_item' => __( 'Edit Ticket Type', 'woothemes'),
'update_item' => __( 'Update Ticket Type', 'woothemes'),
'add_new_item' => __( 'Add New Ticket Type', 'woothemes'),
'new_item_name' => __( 'New Ticket Type', 'woothemes')
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'ticket-type', 'with_front' => false ),
)
);
register_taxonomy( 'ticket_tags',
array('ticket'),
array(
'hierarchical' => false,
'labels' => array(
'name' => __( 'Ticket Tags', 'woothemes'),
'singular_name' => __( 'Ticket Tags', 'woothemes'),
'search_items' => __( 'Search Ticket Tags', 'woothemes'),
'all_items' => __( 'All Ticket Tags', 'woothemes'),
'parent_item' => __( 'Parent Ticket Tag', 'woothemes'),
'parent_item_colon' => __( 'Parent Ticket Tag:', 'woothemes'),
'edit_item' => __( 'Edit Ticket Tag', 'woothemes'),
'update_item' => __( 'Update Ticket Tag', 'woothemes'),
'add_new_item' => __( 'Add New Ticket Tag', 'woothemes'),
'new_item_name' => __( 'New Ticket Tag', 'woothemes')
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array( 'slug' => 'ticket-tag' ),
)
);
}
add_action( 'init', 'woo_supportpress_post_types_init', 0 );
/*-----------------------------------------------------------------------------------*/
/* Admin columns for post types */
/*-----------------------------------------------------------------------------------*/
function woo_supportpress_ticket_columns($old_columns){
$columns = array(
'cb' => '<input type=\"checkbox\" />',
'title' => __('Ticket Title', 'woothemes'),
'incr_number' => __('Ticket ID', 'woothemes'),
'status' => __('Status', 'woothemes'),
'priority' => __('Priority', 'woothemes'),
'type' => __('Type', 'woothemes'),
'author' => __('Submitted by', 'woothemes'),
'assigned' => __('Assigned to', 'woothemes'),
'comments' => $old_columns["comments"],
'date' => __('Date', 'woothemes'),
);
return $columns;
}
add_action( 'custom_woo_supportpress_ticket_columns', 'custom_woo_supportpress_ticket_columns', 10, 2 );
function custom_woo_supportpress_ticket_columns( $column, $post_id ) {
global $post;
switch( $column ) {
/* If displaying the 'incr_number' column. */
case 'incr_number' :
/* Get the post meta. */
$incr_number = get_post_meta($post_id, 'incr_number', true );
break;
}
}
add_filter('manage_edit-ticket_columns', 'woo_supportpress_ticket_columns');
function woo_supportpress_ticket_custom_columns($column) {
global $post;
$ticket_details = woo_supportpress_get_ticket_details( $post->ID );
switch ($column) {
case "status" :
echo get_the_term_list($post->ID, 'ticket_status', '', ', ','');
break;
case "priority" :
echo get_the_term_list($post->ID, 'ticket_priority', '', ', ','');
break;
case "type" :
echo get_the_term_list($post->ID, 'ticket_type', '', ', ','');
break;
case "assigned" :
if ($ticket_details['assigned_to']->ID>0) :
$link = get_author_posts_url( $ticket_details['assigned_to']->ID );
else :
$link = add_query_arg('assigned_to', '0', get_post_type_archive_link('ticket'));
endif;
echo '<a href="'.$link.'">'.$ticket_details['assigned_to']->display_name.'</a>';
break;
case "id" :
echo '#'.$post->ID;
break;
}
}
add_action('manage_ticket_posts_custom_column', 'woo_supportpress_ticket_custom_columns', 2);
require_once locate_template('/lib/ticket-post-type.php'); // Custom Post Types