我通过高级自定义字段为帖子添加了真/假值(独家与策划)。如何将该值显示为帖子列表中的一列(/wp admin/edit.php),以允许编辑器通过该字段快速排序?
我找到了这个例子(http://code.tutsplus.com/articles/add-a-custom-column-in-posts-and-custom-post-types-admin-screen--wp-24934) 用于添加帖子缩略图,但不知道如何调整为拉入和ACF字段。
字段名称为company\\u exclusive,类型为True/False。
任何指点都将不胜感激。
编辑:我找到了此解决方案(http://olliebarker.co.uk/articles/2014/06/displaying-custom-fields-wordpress-admin-post-lists/), 并根据我的需要修改了它的代码,但在创建之后,我没有在wp admin/edit中看到这些字段。php屏幕(在屏幕选项中或可见)。我正在将它添加到我的主题函数中。php。那是正确的地方,对吗?
//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;
}
}
SO网友:Rijo
我使用以下代码指定管理面板产品列表中的特色产品。
add_filter(\'manage_product_posts_columns\', \'hs_product_table_head\');
function hs_product_table_head( $columns ) {
$columns[\'product_featured\'] = \'Featured\';
return $columns;
}
add_action( \'manage_product_posts_custom_column\', \'hs_product_table_content\', 10, 2 );
function hs_product_table_content( $column_name, $post_id ) {
if( $column_name == \'product_featured\' ) {
$featured_product = get_post_meta( $post_id, \'featured_product\', true );
if($featured_product == 1) {
echo "Yes";
}
}
}
要将其用于其他帖子类型,请更改以下代码。例如,帖子类型为“公文包”
add_filter(\'manage_portfolio_posts_columns\', \'hs_portfolio_table_head\');
add_action( \'manage_portfolio_posts_custom_column\', \'hs_portfolio_table_content\', 10, 2 );
SO网友:Julian Alvarado
对于高级自定义字段,请将此代码放入functions.php
:
add_filter( \'manage_faq_posts_columns\', \'set_custom_edit_faq_columns\' );
add_action( \'manage_faq_posts_custom_column\' , \'custom_faq_column\', 10, 2 );
function set_custom_edit_faq_columns($columns) {
unset( $columns[\'author\'] );
$columns[\'is_useful\'] = \'Is Useful\';
$columns[\'is_unless\'] = \'Is Unless\';
return $columns;
}
function custom_faq_column( $column, $post_id ) {
global $post;
switch ( $column ) {
case \'is_useful\' :
if(get_field( "is_useful", $post_id )) {
echo get_field( "is_useful", $post_id );
} else {
echo 0;
}
break;
case \'is_unless\' :
if(get_field( "is_unless", $post_id )) {
echo get_field( "is_unless", $post_id );
} else {
echo 0;
}
break;
}
}
function my_column_register_sortable( $columns ) {
$columns[\'is_useful\'] = \'is_useful\';
$columns[\'is_unless\'] = \'is_unless\';
return $columns;
}
add_filter("manage_edit-faq_sortable_columns", "my_column_register_sortable" );