Skip to content

Instantly share code, notes, and snippets.

@drikusroor
Created December 3, 2023 16:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drikusroor/b6bcea10330189a72c077c700b6787d7 to your computer and use it in GitHub Desktop.
Save drikusroor/b6bcea10330189a72c077c700b6787d7 to your computer and use it in GitHub Desktop.
How to Display Custom Field Values in WordPress Admin for Custom Post Types
<?php
// ... Rest of functions.php
/**
* Add the question code column to the question custom post type.
*/
function add_question_code_column_to_question_cpt($columns) {
$columns['question_code'] = 'Question Code';
return $columns;
}
add_filter('manage_question_posts_columns', 'add_question_code_column_to_question_cpt');
function question_code_column_content($column, $post_id) {
if ($column == 'question_code') {
$question_code = get_post_meta($post_id, 'question_code', true);
echo $question_code;
}
}
add_action('manage_question_posts_custom_column', 'question_code_column_content', 10, 2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment