在wordpress中没有调用add_filter函数

时间:2018-05-02 09:22:27

标签: wordpress custom-post-type add-filter

我在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;
}

1 个答案:

答案 0 :(得分:0)

试试这段代码。

在代码中拼写错误。我将此代码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;
}