{"id":13047114,"date":"2020-06-29T06:00:47","date_gmt":"2020-06-29T06:00:47","guid":{"rendered":"https:\/\/wordpress.org\/support\/topic\/no-value-for-custom-post-type-column\/"},"modified":"2020-06-29T06:06:45","modified_gmt":"2020-06-29T06:06:45","slug":"no-value-for-custom-post-type-column","status":"publish","type":"topic","link":"https:\/\/wordpress.org\/support\/topic\/no-value-for-custom-post-type-column\/","title":{"rendered":"No value for custom post type column"},"content":{"rendered":"<p>I cannot display column values for a custom post type. I use correct filters and actions according to WordPress documentation.<\/p>\n<p>To make sure I&#8217;m doing everything right I&#8217;ve prepared a simple plugin based on examples from official documentation to initiate a custom post type and add a custom column.<br \/>\nUnfortunately, the column I added is still not filled with <code>&quot;lorem ipsum&quot;<\/code>.<\/p>\n<p>Analyzing WordPress code, I noticed that the <code>column_default method<\/code> defined in<br \/>\n<code>wp-admin\/includes\/class-wp-posts-list-table.php<\/code> where the action <code>manage_{$post-&gt;post_type}_posts_custom_column<\/code> is defined is not executed.<\/p>\n<p>https:\/\/i.stack.imgur.com\/VR9Nj.png<\/p>\n<p>Here&#8217;s the full plugin code.<\/p>\n<p>    &#8211; Post type: <code>xpost<\/code><br \/>\n    &#8211; Custom column: <code>xpostcol<\/code><\/p>\n<pre><code>\n&lt;?php\n\/**\n * Plugin Name: XPlugin\n *\/\n\nadd_action(&#039;init&#039;, &#039;xplugin_register_post_type&#039;);\nadd_filter(&#039;manage_xpost_posts_columns&#039;, &#039;xplugin_manage_posts_columns&#039;);\nadd_action(&#039;manage_xpost_posts_custom_column&#039;, &#039;xplugin_manage_posts_custom_column&#039;, 10, 2 );\nregister_activation_hook(__FILE__, &#039;xplugin_register_activation_hook&#039;);\n\nfunction xplugin_register_post_type() {\n    $labels = array(\n        &#039;name&#039;=&gt; &#039;XPosts&#039;\n    );\n\n    $args = array(\n        &#039;labels&#039;             =&gt; $labels,\n        &#039;public&#039;             =&gt; true,\n        &#039;publicly_queryable&#039; =&gt; true,\n        &#039;show_ui&#039;            =&gt; true,\n        &#039;show_in_menu&#039;       =&gt; true,\n        &#039;query_var&#039;          =&gt; true,\n        &#039;rewrite&#039;            =&gt; array( &#039;slug&#039; =&gt; &#039;xpost&#039; ),\n        &#039;capability_type&#039;    =&gt; &#039;post&#039;,\n        &#039;has_archive&#039;        =&gt; true,\n        &#039;hierarchical&#039;       =&gt; false,\n        &#039;menu_position&#039;      =&gt; null,\n        &#039;supports&#039;           =&gt; array( &#039;title&#039;, &#039;editor&#039;, &#039;author&#039;, &#039;thumbnail&#039;, &#039;excerpt&#039;, &#039;comments&#039; ),        \n    );\n\n    register_post_type( &#039;xpost&#039;, $args );\n}\n\nfunction xplugin_register_activation_hook() {\n    xplugin_register_post_type();\n    flush_rewrite_rules();\n}\n\nfunction xplugin_manage_posts_columns($columns) {\n    unset($columns[&#039;author&#039;]);\n    $new_columns = array(&#039;xpostcol&#039; =&gt; &#039;XPost Column&#039;);\n    return array_merge($columns, $new_columns);\n}\n\nfunction xplugin_manage_posts_custom_column($column, $post_id) {\n    switch ($column) {\n        case &#039;xpostcol&#039; :\n            echo &#039;Lorem ipsum&#039;;\n            break;\n    }    \n}\n<\/code><\/pre>\n","protected":false},"template":"","class_list":["post-13047114","topic","type-topic","status-publish","hentry"],"jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13047114","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic"}],"about":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/types\/topic"}],"version-history":[{"count":3,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13047114\/revisions"}],"predecessor-version":[{"id":13047138,"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/topic\/13047114\/revisions\/13047138"}],"wp:attachment":[{"href":"https:\/\/wordpress.org\/support\/wp-json\/wp\/v2\/media?parent=13047114"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}