do_action( "manage_{$post->post_type}_posts_custom_column", string $column_name, int $post_id )

Fires for each custom column of a specific post type in the Posts list table.


Description Description

The dynamic portion of the hook name, $post->post_type, refers to the post type.


Parameters Parameters

$column_name

(string) The name of the column to display.

$post_id

(int) The current post ID.


Top ↑

Source Source

File: wp-admin/includes/class-wp-posts-list-table.php

View on Trac


Top ↑

Changelog Changelog

Changelog
Version Description
3.1.0 Introduced.


Top ↑

User Contributed Notes User Contributed Notes

  1. Skip to note 1 content
    Contributed by Andrija Naglic
    
    // let's say we have a CPT called 'product'
    function product_custom_column_values( $column, $post_id ) {
    
        switch ( $column ) {
    
    		// in this example, a Product has custom fields called 'product_number' and 'product_name'
            case 'product_number'	:
            case 'product_name' 	:
                echo get_post_meta( $post_id , $column , true );
            break;
    
    		// in this example, $buyer_id is post ID of another CPT called "buyer"
            case 'product_buyer' 	:
                $buyer_id = get_post_meta( $post_id , $column , true );
                if( $buyer_id ){
                    echo get_post_meta( $buyer_id , 'buyer_name' , true );
                } else {
                    echo '<div class="dashicons dashicons-minus"></div>';
                }
            break;
    
        }
    }
    add_action( 'manage_product_posts_custom_column' , 'product_custom_column_values', 10, 2 );
    

    For further management of columns, check:

    https://developer.wordpress.org/reference/hooks/manage_post_type_posts_columns/
    To add/remove/rename columns

    https://developer.wordpress.org/reference/hooks/list_table_primary_column/
    To set the primary (default) column

You must log in before being able to contribute a note or feedback.