WP_Posts_List_Table::column_default( WP_Post $item, string $column_name )

In this article

Handles the default column output.

Parameters

$itemWP_Postrequired
The current WP_Post object.
$column_namestringrequired
The current column name.

Source

public function column_default( $item, $column_name ) {
	// Restores the more descriptive, specific name for use within this method.
	$post = $item;

	if ( 'categories' === $column_name ) {
		$taxonomy = 'category';
	} elseif ( 'tags' === $column_name ) {
		$taxonomy = 'post_tag';
	} elseif ( str_starts_with( $column_name, 'taxonomy-' ) ) {
		$taxonomy = substr( $column_name, 9 );
	} else {
		$taxonomy = false;
	}

	if ( $taxonomy ) {
		$taxonomy_object = get_taxonomy( $taxonomy );
		$terms           = get_the_terms( $post->ID, $taxonomy );

		if ( is_array( $terms ) ) {
			$term_links = array();

			foreach ( $terms as $t ) {
				$posts_in_term_qv = array();

				if ( 'post' !== $post->post_type ) {
					$posts_in_term_qv['post_type'] = $post->post_type;
				}

				if ( $taxonomy_object->query_var ) {
					$posts_in_term_qv[ $taxonomy_object->query_var ] = $t->slug;
				} else {
					$posts_in_term_qv['taxonomy'] = $taxonomy;
					$posts_in_term_qv['term']     = $t->slug;
				}

				$label = esc_html( sanitize_term_field( 'name', $t->name, $t->term_id, $taxonomy, 'display' ) );

				$term_links[] = $this->get_edit_link( $posts_in_term_qv, $label );
			}

			/**
			 * Filters the links in `$taxonomy` column of edit.php.
			 *
			 * @since 5.2.0
			 *
			 * @param string[]  $term_links Array of term editing links.
			 * @param string    $taxonomy   Taxonomy name.
			 * @param WP_Term[] $terms      Array of term objects appearing in the post row.
			 */
			$term_links = apply_filters( 'post_column_taxonomy_links', $term_links, $taxonomy, $terms );

			echo implode( wp_get_list_item_separator(), $term_links );
		} else {
			echo '<span aria-hidden="true">&#8212;</span><span class="screen-reader-text">' . $taxonomy_object->labels->no_terms . '</span>';
		}
		return;
	}

	if ( is_post_type_hierarchical( $post->post_type ) ) {

		/**
		 * Fires in each custom column on the Posts list table.
		 *
		 * This hook only fires if the current post type is hierarchical,
		 * such as pages.
		 *
		 * @since 2.5.0
		 *
		 * @param string $column_name The name of the column to display.
		 * @param int    $post_id     The current post ID.
		 */
		do_action( 'manage_pages_custom_column', $column_name, $post->ID );
	} else {

		/**
		 * Fires in each custom column in the Posts list table.
		 *
		 * This hook only fires if the current post type is non-hierarchical,
		 * such as posts.
		 *
		 * @since 1.5.0
		 *
		 * @param string $column_name The name of the column to display.
		 * @param int    $post_id     The current post ID.
		 */
		do_action( 'manage_posts_custom_column', $column_name, $post->ID );
	}

	/**
	 * Fires for each custom column of a specific post type in the Posts list table.
	 *
	 * The dynamic portion of the hook name, `$post->post_type`, refers to the post type.
	 *
	 * Possible hook names include:
	 *
	 *  - `manage_post_posts_custom_column`
	 *  - `manage_page_posts_custom_column`
	 *
	 * @since 3.1.0
	 *
	 * @param string $column_name The name of the column to display.
	 * @param int    $post_id     The current post ID.
	 */
	do_action( "manage_{$post->post_type}_posts_custom_column", $column_name, $post->ID );
}

Hooks

do_action( ‘manage_pages_custom_column’, string $column_name, int $post_id )

Fires in each custom column on the Posts list table.

do_action( ‘manage_posts_custom_column’, string $column_name, int $post_id )

Fires in each custom column in the Posts list table.

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.

apply_filters( ‘post_column_taxonomy_links’, string[] $term_links, string $taxonomy, WP_Term[] $terms )

Filters the links in $taxonomy column of edit.php.

Changelog

VersionDescription
5.9.0Renamed $post to $item to match parent class for PHP 8 named parameter support.
4.3.0Introduced.

User Contributed Notes

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