wordpress - add_filter 函数没有在 wordpress 中被调用
问题描述
我在 wordpress 文件中创建了一个 custom_post_type。但是我在添加过滤功能时遇到了麻烦。过滤功能似乎没有被唤起?alpha_set_contact_coloumns() 没有提供任何结果。
<?php
$contact = get_option( 'activate_contact' );
if(@$contact == 1){
add_action( 'init', 'alpha_contact_custom_post_type' );
add_filter( 'manage_alpha-contact_posts_coloumns', 'alpha_set_contact_coloumns' );
}
function alpha_contact_custom_post_type() {
$labels = array(
'name' => 'Messages',
'singular_name' => 'Message',
'menu_name' => 'Messages',
'name_admin_bar'=> 'Message'
);
$args = array(
'labels' => $labels,
'show_ui' => true,
'show_in_menu' => true,
'capability_type'=> 'post',
'hierarchical' => false,
'menu_position' => 26,
'menu_icon' => 'dashicons-email-alt',
'supports' => array('title', 'editor', 'author')
);
register_post_type( 'alpha-contact', $args );
}
function alpha_set_contact_coloumns( $coloumns ) {
unset( $coloumns['author']);
return $coloumns;
}
解决方案
试试这个代码。
代码中的拼写错误。我manage_contact_posts_coloumns
用manage_alpha-contact_posts_columns
.
它不是列coloumns
。
$contact = get_option( 'activate_contact' );
if(@$contact == 1){
add_action( 'init', 'alpha_contact_custom_post_type' );
add_filter( 'manage_alpha-contact_posts_columns', 'alpha_set_contact_coloumns' );
}
function alpha_contact_custom_post_type() {
$labels = array(
'name' => 'Messages',
'singular_name' => 'Message',
'menu_name' => 'Messages',
'name_admin_bar'=> 'Message'
);
$args = array(
'labels' => $labels,
'show_ui' => true,
'show_in_menu' => true,
'capability_type'=> 'post',
'hierarchical' => false,
'menu_position' => 26,
'menu_icon' => 'dashicons-email-alt',
'supports' => array('title', 'editor', 'author')
);
register_post_type( 'alpha-contact', $args );
}
function alpha_set_contact_coloumns( $coloumns ) {
unset( $coloumns['author']);
return $coloumns;
}
推荐阅读
- mysql - XAMPP 无法启动 MySQL(没有应用程序在同一端口上运行)
- amazon-web-services - AWS s3 ls 命令返回错误:拒绝访问
- c - 指令将跨越 PC
- python - 尝试从一系列字典中检索键时出现“类型错误:列表索引必须是整数或切片,而不是 str”
- azure - 使用 Azure Yaml 管道在正文中调用带有秘密变量的 powershell RestMethod
- java - CardView cardElevation 在 CardView 内绘制随机正方形
- python-3.x - Groupby并在Python中从左侧开始查找公共字符串部分
- mongodb - 如何在 mongodb 聚合查询中模拟循环?
- r - Shiny observe() 函数不适用于 Shinymanager
- mysql - AWS Aurora Serverless MySQL 无故挂起