Support

Account

Home Forums Backend Issues (wp-admin) adding date to admin columns

Solved

adding date to admin columns

  • I am having problems adding dates to my admin columns

    I’ve got it added but the date always shows as “10212016” instead of October 21, 2016.

    I have my event_date field set to display and return as “October 21, 2016”

    this is my code:

    /*

    * Add columns to forum post list
    */
    function add_acf_columns ( $columns ) {
       return array_merge ( $columns, array ( 
         'event_date' => __ ( 'date of event' ),
         'event_location'   => __ ( 'location' ) 
       ) );
     }
    //add_filter ( 'manage_edit-cr3ativconference_columns', 'add_acf_columns' );
    
    /*
    * Add content to forum post list column
    */
    function forum_custom_column ( $column, $post_id ) {
       switch ( $column ) {
         case 'event_date':
           echo get_post_meta ( $post_id, 'event_date', true );
           break;
         case 'event_location':
           echo get_post_meta ( $post_id, 'event_location', true );
           break;
       }
     }
    add_action ( 'manage_cr3ativconference_posts_custom_column', 'forum_custom_column', 10, 2 );
  • Hi @rudtek

    That’s because you were using the get_post_meta() function instead of the get_field() function. This page should give you more idea about it: https://www.advancedcustomfields.com/resources/displaying-custom-field-values-in-your-theme/. So, you should be able to do it like this:

    function forum_custom_column ( $column, $post_id ) {
       switch ( $column ) {
         case 'event_date':
           echo get_field( 'event_date', $post_id );
           break;
         case 'event_location':
           echo get_field( 'event_location', $post_id );
           break;
       }
     }
    add_action ( 'manage_cr3ativconference_posts_custom_column', 'forum_custom_column', 10, 2 );

    I hope this helps 🙂

  • is there any way to do with with repeater fields, so i could say load all the speakers who are on that forum post?

  • Hi @rudtek

    For the repeater field, kindly check the documentation here: https://www.advancedcustomfields.com/resources/repeater/.

    Thanks 🙂

Viewing 5 posts - 1 through 5 (of 5 total)

The topic ‘adding date to admin columns’ is closed to new replies.