Created
December 3, 2023 16:53
-
-
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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