Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #889852

    Hi guys!
    I used CPT UI and ACF to create a CPT with a few custom fields. I now would love to add those columns to my admin post page for that custom post.

    I wrote adjusted the following code:

    // Tabellenkopf und -fuß um Felder erweitern
    add_filter('manage_edit-juschu_imp_kundnrs','kb_edit_admin_kundnrs') ;
    function kb_edit_admin_kundnrs($kundnrs) {
      $kundnrs = array(
        'cb' => '<input type="checkbox" />',
        'title' => __('Title'),
        'kundnr' => Kundennummer,
        'author' => __('Author'),
        'comments' => '<span class="vers comment-grey-bubble" title="' . __( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>',
        'date' => __('Date')
      );
      return $kundnrs;
    }
    
    // Inhalte aus benutzerdefinierten Feldern auslesen und den Spalten hinzufügen
    add_action ('manage_juschu_imp_posts_custom_kundnr','kb_post_custom_kundnrs');
    function kb_post_custom_kundnrs($kundnr) {
      global $post;
      $custom = get_post_custom();
      switch ($kundnr) {
        case "kundnr":
          $kb_field = get_post_meta($post->ID, 'knr', true );
          echo $kb_field;
        break;
      }
    }
    
    // Hinzugefügte Spalten sortierbar machen
    add_filter( 'manage_edit-juschu_imp_sortable_kundnrs', 'kb_post_sortierbare_kundnrs' );
    function kb_post_sortierbare_kundnrs( $kundnrs ) {
      $kundnrs['kundnr'] = 'knr';
      return $kundnrs;
    }

    Which i got here: https://blog.kulturbanause.de/2016/11/wordpress-admin-columns-um-custom-fields-erweitern/

    But I can’t get it to work. I am working on my localhost, so i cant provide you with a link. Can you please tell me where to post that code? functions.php didn_t work.

    Thank you.

    #890263

    Hey,

    Please try changing the code to following one

    // Tabellenkopf und -fuß um Felder erweitern
    add_filter('manage_edit-juschu_imp_columns','kb_edit_admin_kundnrs') ;
    function kb_edit_admin_kundnrs($kundnrs) {
      $kundnrs = array(
        'cb' => '<input type="checkbox" />',
        'title' => __('Title'),
        'kundnr' => Kundennummer,
        'author' => __('Author'),
        'comments' => '<span class="vers comment-grey-bubble" title="' . __( 'Comments' ) . '"><span class="screen-reader-text">' . __( 'Comments' ) . '</span></span>',
        'date' => __('Date')
      );
      return $kundnrs;
    }
    
    // Inhalte aus benutzerdefinierten Feldern auslesen und den Spalten hinzufügen
    add_action ('manage_juschu_imp_posts_custom_column','kb_post_custom_kundnrs');
    function kb_post_custom_kundnrs($kundnr) {
      global $post;
      $custom = get_post_custom();
      switch ($kundnr) {
        case "kundnr":
          $kb_field = get_post_meta($post->ID, 'knr', true );
          echo $kb_field;
        break;
      }
    }
    
    // Hinzugefügte Spalten sortierbar machen
    add_filter( 'manage_edit-juschu_imp_sortable_columns', 'kb_post_sortierbare_kundnrs' );
    function kb_post_sortierbare_kundnrs( $kundnrs ) {
      $kundnrs['kundnr'] = 'knr';
      return $kundnrs;
    }

    Best regards,
    Yigit

    #890901

    Thank you, that helped!

    #890930

    Hi,

    You are welcome! Let us know if you have any other questions or issues :)

    Best regards,
    Yigit

Viewing 4 posts - 1 through 4 (of 4 total)
  • The topic ‘Add Custom Columns to Admin Tabe of Custom Posts’ is closed to new replies.