Support

Account

Home Forums Reply To:

  • I’m trying to add ACF information to a column in the edit screen for a custom post type (Events) via the functions.php file of my theme. The issue is that the info I’m looking to add is from a post_object field and is returning the post ID rather than the title.

    Here’s the code I’m using:

    function change_columns( $cols ) {
      $cols = array(
        'cb'          => '<input type="checkbox" />',
        'event_date'  => __( 'Event Date', 'trans' ),
        'venue'       => __( 'Event', 'trans' ),
        'city'        => __( 'City', 'trans' ),
        'artist'      => __( 'Artist', 'trans' ),
      );
      return $cols;
    }
    add_filter( "manage_event_posts_columns", "change_columns" );
    
    function custom_columns( $column, $post_id ) {
      switch ( $column ) {
        case "event_date":
          $date = get_field('event_date');          
          echo date("F j, Y (l)", strtotime($date));
          break;
        case "venue":
          echo get_post_meta( $post_id, 'venue_name', true);
          break;
        case "city":
          echo get_post_meta( $post_id, 'city_&_country', true);
          break;
        case "artist":
          echo get_post_meta( $post_id, 'artist', true);
          break;
      }
    }
    add_action( "manage_posts_custom_column", "custom_columns", 10, 2 );

    The result can be seen in the attached screenshot. How can I echo the title of the post_object called in the “artist” column instead of its ID?