Adding Category/Tag/Taxonomy Support to Images/Media

Here’s how I recently added a custom taxonomy to the media library as a sortable column: // Add a new column add_filter(‘manage_media_columns’, ‘add_topic_column’); function add_topic_column($posts_columns) { $posts_columns[‘att_topic’] = _x(‘Topic’, ‘column name’); return $posts_columns; } // Register the column as sortable function topic_column_register_sortable( $columns ) { $columns[‘att_topic’] = ‘att_topic’; return $columns; } add_filter( ‘manage_upload_sortable_columns’, ‘topic_column_register_sortable’ ); … Read more

Make custom column sortable

Make sure to change MY_POST_TYPE, MY_CUSTOM_COLUMN and MY_META_KEY to the actual values. First, add your custom column. Unset the date and set it again to keep it in the last column. You can skip this step. <?php function my_manage_MY_POST_TYPE_columns( $columns ) { // save date to the variable $date = $columns[‘date’]; // unset the ‘date’ … Read more

Replacing the title in admin list table

1. Change post title in post list column I misunderstood what you wanted – obviously. You can do that like this: add_action( ‘admin_head-edit.php’, ‘wpse152971_edit_post_change_title_in_list’ ); function wpse152971_edit_post_change_title_in_list() { add_filter( ‘the_title’, ‘wpse152971_construct_new_title’, 100, 2 ); } function wpse152971_construct_new_title( $title, $id ) { //print_r( $title ); //print_r( $id ); return ‘new’; } Making use of the admin_head-$hook_suffix … Read more

Custom columns for taxonomy list table

The manage_{TAXONOMY}_custom_column filter hook passes 3 arguments: $content $column_name $term_id So try this: function add_book_place_column_content($content,$column_name,$term_id){ $term= get_term($term_id, ‘book_place’); switch ($column_name) { case ‘foo’: //do your stuff here with $term or $term_id $content=”test”; break; default: break; } return $content; } add_filter(‘manage_book_place_custom_column’, ‘add_book_place_column_content’,10,3);

How do I set the default admin sort order for a custom post type to a custom column?

Solution from a cross post over at StackExchange from @birgire: The problem is that you run the clientarea_default_order callback too late. To fix that you only have to change the priority from the default one that’s 10: add_action( ‘pre_get_posts’,’clientarea_default_order’); to the priority of 9: add_action( ‘pre_get_posts’,’clientarea_default_order’, 9 ); But you don’t actually need two pre_get_posts … Read more

Adding custom columns to custom post types

The hooks to create custom columns and their associated data for a custom post type are manage_{$post_type}_posts_columns and manage_{$post_type}_posts_custom_column respectively, where {$post_type} is the name of the custom post type. This example from the documentation removes the author column and adds a taxonomy and meta data column: // Add the custom columns to the book … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)