[wp-hackers] edit.php custom post type customisations
Erick Hitter
ehitter at gmail.com
Thu Mar 3 13:06:59 UTC 2011
There are two hooks, one action and one filter, that let you modify the
columns on the edit screen. The filter *manage_posts_columns* provides
access to the columns array, while the action *manage_posts_custom_column* is
used to add content to the new column(s).
The code below is used specifically for a custom post type. Since I
abstracted this from a custom post type class, there are some references to
class properties. This example adds a column to show custom taxonomy terms
associated with the posts, as well as their order.
function filter_manage_posts_columns( $columns ) {
global $pagenow;
if( $pagenow == 'edit.php' && isset( $_GET[ 'post_type' ] ) && $_GET[
'post_type' ] == $this->post_type ) {
$columns_a = array_slice( $columns, 0, 2 );
$columns_a[ $this->reports_taxonomy ] = 'Report Categories';
$columns_a[ 'menu_order' ] = 'Order';
$columns_b = array_slice( $columns, 2 );
$columns = array_merge( $columns_a, $columns_b );
}
return $columns;
}
add_filter( 'manage_posts_columns', array( $this,
'filter_manage_posts_columns' ) );
function action_manage_posts_custom_column( $column, $postid ) {
if( $column == $this->reports_taxonomy ) {
$report_categories = get_the_terms( $postid, $this->reports_taxonomy );
if( is_array( $report_categories ) && !empty( $report_categories ) ) {
$i = 1;
foreach( $report_categories as $report_category ) {
echo $report_category->name;
if( $i < count( $report_categories ) ) echo ', ';
$i++;
}
}
}
if( $column == 'menu_order' ) {
global $post;
echo $post->menu_order;
}
}
add_action( 'manage_posts_custom_column', array( $this,
'action_manage_posts_custom_column' ), 10, 2 );
Hope this helps,
Erick
On Thu, Mar 3, 2011 at 04:51, aditya sharma <sharmaaditya333 at gmail.com>wrote:
> For hooking onto the edit posts screen, the following hook will do that for
> you..
>
> add_action( 'admin_print_styles-edit.php', 'your-function-callback' );
>
> Replace your-function-callback with the name of the function you wish to
> call with the action.
>
> Warm Regards
> Aditya Sharma
>
>
>
>
> On Thu, Mar 3, 2011 at 1:00 PM, Paul Gibbs <djpaul at gmail.com> wrote:
>
> > Hi all
> > What's the best way to add a column to the edit.php?post_type=blah screen
> > in 3.1?
> >
> > Regards
> > Paul Gibbs
> > _______________________________________________
> > wp-hackers mailing list
> > wp-hackers at lists.automattic.com
> > http://lists.automattic.com/mailman/listinfo/wp-hackers
> >
> _______________________________________________
> wp-hackers mailing list
> wp-hackers at lists.automattic.com
> http://lists.automattic.com/mailman/listinfo/wp-hackers
>
More information about the wp-hackers
mailing list