Search code examples
phpwordpressdocker

Wordpress - No value for custom post type column


I cannot display column values for a custom post type. I use correct filters and actions according to WordPress documentation.

To make sure I'm doing everything right I've prepared a simple plugin based on examples from official documentation to initiate a custom post type and add a custom column.
Unfortunately, the column I added is still not filled with "lorem ipsum".

Analyzing Wordpress code, I noticed that the column_default method defined in
wp-admin/includes/class-wp-posts-list-table.php where the action manage_{$post->post_type}_posts_custom_column is defined is not executed.

enter image description here

Here's the full plugin code.

  • Post type: xpost
  • Custom column: xpostcol
<?php
/**
 * Plugin Name: XPlugin
 */

add_action('init', 'xplugin_register_post_type');
add_filter('manage_xpost_posts_columns', 'xplugin_manage_posts_columns');
add_action('manage_xpost_posts_custom_column', 'xplugin_manage_posts_custom_column', 10, 2 );
register_activation_hook(__FILE__, 'xplugin_register_activation_hook');

function xplugin_register_post_type() {
    $labels = array(
        'name'=> 'XPosts'
    );

    $args = array(
        'labels'             => $labels,
        'public'             => true,
        'publicly_queryable' => true,
        'show_ui'            => true,
        'show_in_menu'       => true,
        'query_var'          => true,
        'rewrite'            => array( 'slug' => 'xpost' ),
        'capability_type'    => 'post',
        'has_archive'        => true,
        'hierarchical'       => false,
        'menu_position'      => null,
        'supports'           => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' ),        
    );

    register_post_type( 'xpost', $args );
}

function xplugin_register_activation_hook() {
    xplugin_register_post_type();
    flush_rewrite_rules();
}

function xplugin_manage_posts_columns($columns) {
    unset($columns['author']);
    $new_columns = array('xpostcol' => 'XPost Column');
    return array_merge($columns, $new_columns);
}

function xplugin_manage_posts_custom_column($column, $post_id) {
    switch ($column) {
        case 'xpostcol' :
                echo 'Lorem ipsum';
            break;
    }    
}


Solution

  • Plugin works incorrectly when I run WordPress container from the official Docker image. In case of running custom container based on Apache + PHP + MySQL and manual WordPress installation, the plugin works fine.