【问题标题】:add_filter function not getting called in wordpressadd_filter 函数没有在 wordpress 中被调用
【发布时间】:2018-05-02 09:22:27
【问题描述】:

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

【问题讨论】:

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


【解决方案1】:

试试这个代码。

代码中的拼写错误。我用manage_alpha-contact_posts_columns替换了这段代码manage_contact_posts_coloumns

它是而不是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;
}

【讨论】:

  • 它有帮助。错过了关键字“列”
  • 我没有声望支持您的回答。对不起
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-10-27
  • 1970-01-01
  • 2016-12-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多