1. Home
  2. /
  3. Forum

Forum

How to add custom c...
 
Notifications
Clear all

How to add custom columns in WP admin

2 Posts
1 Users
0 Reactions
497 Views
(@devsam)
Member Admin
Joined: 5 years ago
Posts: 18
Topic starter  

Add the following piece of code in your themes functions.php 

/*
 * Add columns to exhibition post list
 */
 function add_acf_columns ( $columns ) {
   return array_merge ( $columns, array ( 
     'lc_event_start_date' => __ ( 'Starts' ),
     'lc_event_end_date'   => __ ( 'Ends' ) 
   ) );
 }
 add_filter ( 'manage_local_events_posts_columns', 'add_acf_columns' );


  /*
 * Add columns to exhibition post list
 */
 function local_events_custom_column ( $column, $post_id ) {
   switch ( $column ) {
     case 'lc_event_start_date':
       echo date('m-d-Y', strtotime( get_post_meta ( $post_id, 'lc_event_start_date', true ) ) ).' '.get_post_meta ( $post_id, 'lc_event_start_time', true );
       break;
     case 'lc_event_end_date':
	   $time = get_post_meta ( $post_id, 'lc_event_end_date', true );
	   if( !empty($time)) {
		echo date('m-d-Y', strtotime( $time ) ).' '.get_post_meta ( $post_id, 'lc_event_end_time', true );
	   }
       break;
   }
 }
 add_action ( 'manage_local_events_posts_custom_column', 'local_events_custom_column', 10, 2 );

   
Quote
(@devsam)
Member Admin
Joined: 5 years ago
Posts: 18
Topic starter  
Posted by: @manager

Add the following piece of code in your themes functions.php 

/*
 * Add columns to exhibition post list
 */
 function add_acf_columns ( $columns ) {
   return array_merge ( $columns, array ( 
     'lc_event_start_date' => __ ( 'Starts' ),
     'lc_event_end_date'   => __ ( 'Ends' ) 
   ) );
 }
 add_filter ( 'manage_local_events_posts_columns', 'add_acf_columns' );


  /*
 * Add columns to exhibition post list
 */
 function local_events_custom_column ( $column, $post_id ) {
   switch ( $column ) {
     case 'lc_event_start_date':
       echo date('m-d-Y', strtotime( get_post_meta ( $post_id, 'lc_event_start_date', true ) ) ).' '.get_post_meta ( $post_id, 'lc_event_start_time', true );
       break;
     case 'lc_event_end_date':
	   $time = get_post_meta ( $post_id, 'lc_event_end_date', true );
	   if( !empty($time)) {
		echo date('m-d-Y', strtotime( $time ) ).' '.get_post_meta ( $post_id, 'lc_event_end_time', true );
	   }
       break;
   }
 }
 add_action ( 'manage_local_events_posts_custom_column', 'local_events_custom_column', 10, 2 );

Replace "local_events" with your custom post slug.
And, "lc_event_end_date" are ACF fields.


   
ReplyQuote
Share:
Reviews & Ratings Get your stoe online with Shopify in 60 minutes Shop Now