Home › Forums › Backend Issues (wp-admin) › Adding ACF Fields to Post Listing (wp-admin/edit.php)
I’ve got a True/False value added to posts (Exclusive versus Curated) that was added via Advanced Custom Fields. How do I get that value to show up as a column on the Post list (/wp-admin/edit.php) to allow editors to quickly sort via that field?
I found this example (http://code.tutsplus.com/articles/add-a-custom-column-in-posts-and-custom-post-types-admin-screen–wp-24934) for adding the post thumbnail, but do not know how to adjust to pull and ACF field in instead.
Field name is company_exclusive and type is True/False.
Any pointers would be appreciated.
Edit: I found this solution (http://olliebarker.co.uk/articles/2014/06/displaying-custom-fields-wordpress-admin-post-lists/), and adapted its code to my needs, but after creating this, I’m not seeing the fields in on wp-admin/edit.php screen (either in Screen options or visible). I’m adding it to my theme’s functions.php. That is the right place, correct?
//Adds ACF fields to Post List
add_filter('posts_columns', 'custom_posts_table_head');
function custom_posts_table_head( $columns ) {
$columns['author_name'] = 'Author Name';
$columns['company_exclusive'] = 'Company Exclusive?';
$columns['region'] = 'Region';
$columns['article_excerpt_title'] = 'Article Excerpt Title';
return $columns;
}
add_action( 'posts_columns', 'custom_posts_table_content', 10, 2);
function bs_projects_table_content( $column_name, $post_id ) {
if( $column_name == 'author_name' ) {
$author_name = get_post_meta( $post_id, 'author_name', true );
echo $author_name;
}
if( $column_name == 'company_exclusive' ) {
$company_exclusive = get_post_meta( $post_id, 'company_exclusive', true );
if( $company_exclusive == '1' ) { echo 'Yes'; } else { echo 'No'; }
}
if( $column_name == 'region' ) {
$region = get_post_meta( $post_id, 'region', true );
echo $region;
}
if( $column_name == 'article_excerpt_title' ) {
$article_excerpt_title = get_post_meta( $post_id, 'article_excerpt_title', true );
echo $article_excerpt_title;
}
}
You’re using the wrong hooks for your filter and action. The first link gives these hooks.
The hook that you need to use to add columns is
manage_posts_columns
and the hook for the column content is
manage_posts_custom_column
Look at the function name and hook.
Should be:
add_action( 'posts_columns', 'bs_projects_table_content', 10, 2);
or
function custom_posts_table_content( $column_name, $post_id ) {...}
You must be logged in to reply to this topic.
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!
🚨 The 2023 ACF Annual Survey closes tomorrow! This is your last chance to complete the survey and help guide the evolution of ACF. https://t.co/0cgr9ZFOJ5
— Advanced Custom Fields (@wp_acf) May 18, 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.