wordpresscustom-post-typeadd-filter

add_filter function not getting called in wordpress


I have created a custom_post_type in wordpress file. But I have trouble in adding a filter function. The filter function does not seem to be evoked? alpha_set_contact_coloumns() is not providing any result.

<?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;
}

Solution

  • Try this code.

    Spelling mistake in code. I replaced this code manage_contact_posts_coloumns with manage_alpha-contact_posts_columns.

    it is columns not 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;
    }