Home › Forums › Backend Issues (wp-admin) › Having trouble adding ACF field to admin columns › Reply To: Having trouble adding ACF field to admin columns
The error I meant was the $column_name
variable you used instead of $column
and the elseif
logic instead of else
. If your custom post type is “post_staff”, then you should be able to do it like this:
function my_page_columns($columns)
{
$columns = array(
'cb' => '<input type="checkbox" />',
'title' => 'Last Name',
'first' => 'First Name',
'date' => 'Date',
);
return $columns;
}
function my_custom_columns($column)
{
global $post;
if ($column == 'first') {
echo get_field( "first_name", $post->ID );
}
else {
echo '';
}
}
add_action("manage_post_staff_posts_custom_column", "my_custom_columns");
add_filter("manage_post_staff_posts_columns", "my_page_columns");
I said it’s related to WordPress because this code:
echo get_field( "first_name", $post->ID );
should show the correct value. The only issue is how you show it.
Also, could you please set WP_DEBUG to true to see any error messages on the page? Please take a look at this page to learn how to set it: https://codex.wordpress.org/Debugging_in_WordPress.
I hope this makes sense 🙂
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
Accordions are a great way to group related information while allowing users to interactively show and hide content. In this video, Damon Cook goes in-depth on how to create an accessible accordion block using ACF PRO’s Repeater field.https://t.co/RXT0g25akN
— Advanced Custom Fields (@wp_acf) March 2, 2023
© 2023 Advanced Custom Fields.
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.