Make custom post type column sortable

My site has two custom types: Auction and Lot. Lots are connected to an Auction via the post_parent field. I added an Auction column to the Lots list in the admin area. function theme_lot_custom_columns($columns){ $new = array(); foreach($columns as $key => $value) { if ($key=='date') { // Put the Auction column before the Date column $new['auction'] = __('Auction'); } $new[$key] = $value; } return $new; } add_filter('manage_lot_posts_columns', 'theme_lot_custom_columns'); function theme_lot_custom_column($column, $post_id) { if ($column === 'auction'){ $post = get_post($post_id); if …
Category: Web

Display Custom Column in CPT Taxonomy

I am trying to add a column to one of my custom post types, but only on the edit taxonomy page. I have a taxonomy registered called "event-categories" for my custom post type "events". I can successfully add the custom column to the custom post type edit screen, but can't seem to get the hook to work on the edit taxonomy page. Digging through some of the core, I was able to locate the hook $taxonomies = apply_filters( "manage_taxonomies_for_{$post_type}_columns", $taxonomies, …
Category: Web

Split content into multiple columns using more tag?

First of, this is pretty much an exact duplicate of: Split columns into three+ divs? But the given solution does not work (returns blank). I'm guessing it collides with qTranslate which adds some really weird comments to the html, but i'm not sure. I found a great code snippet that simply splits the content into pieces by the more tag. The problem is it seems to only split into two columns. It ignores the rest of the more tags. I …
Category: Web

How to set 'column-primary' to backoffice 2nd column by default

I'm customizing the way custom posts are displayed in the backoffice. I'm trying to shift the section that appear on hover (I'm refering to the four buttons Edit, Quick edit, Trash, Preview) in the first column to the second one. The reason is that the section, even if is hidden, takes up space vertically. It seems that the edit section is assigned to the column that is signed with the class column-primary, so I'd like to assign that class to …
Category: Web

custom filtering admin columns

i'm trying to add custom filters to a CPT job-offer, for example, i'm starting by locations. the filters works fine except when i try to filter by all locations. this is my code function add_custom_filter_tablenav($post_type){ global $wpdb; /** Ensure this is the correct Post Type*/ if($post_type !== 'job-offer') return; /** Grab the results from the DB */ $query = $wpdb->prepare(' SELECT DISTINCT pm.meta_value FROM %1$s pm LEFT JOIN %2$s p ON p.ID = pm.post_id WHERE pm.meta_key = "%3$s" AND p.post_status …
Category: Web

Is it possible to create column width presets in Gutenberg?

Gutenberg gives you some good choices out of the box but is it possible to add a custom preset? I understand I can change the columns manually but was hoping for a preset to make it easier on the client. My other thought was just manually change the 70/30 one to be more 80/20 in the CSS but again for lack of a better option. Any options as far as adding a preset?
Category: Web

Adding custom columns to custom post types

I've done this previously but I've forgotten the name of the hook, and can't find it anywhere... What I'm trying to do is add some custom columns in the listing of a custom post type in the admin. For example, in the admin, click on articles, I want to add custom column there.
Category: Web

Make custom column sortable

I have a added custom column to a custom post type, and it works fine. I just want it to sort the names by title, so I tried this, function sortable_custom_columns( $columns ) { $columns['custom_column'] = 'title'; return $columns; } add_filter( 'manage_edit-custom_sortable_columns', 'sortable_custom_columns' ); However, that is returning very random sorting. I think it may have to do with the content of the column? Which I render like this; function location_column_content( $column, $post_id ) { switch ( $column ) { …
Category: Web

Custom taxonomy - custom sortable column

I've created custom taxonomy called 'cities' where you can add cities and added custom field ( radio button ) with 2 options: 'Yes' and 'No' ( never mind what that is ). Everythins is ok, I can get that value and other stuff. Later on I came with idea to add a sortable column ( Like 'Name', 'Slug', 'Posts' etc. ). I've managed to create that column, make it sortable but don't know how to sort those cities by that …
Category: Web

Search & column order by meta value in admin

So, my posts have a custom field named "company" and I would like to have a sortable column for this field in the admin area list of posts and also be able to search posts by it's content. I've been able to do both things but not at the same time. That is: the search works but when I try to order it by the company column it goes blank. If I don't do a search, the ordering works fine …
Category: Web

WP List Table custom column wrapping issue

A table list of Products menu of WooCommerce plugin has a custom/extra column, which breaks the text inside it (image-1). If I change the default overflow-wrap: break-word to normal, the text overflows the column's borders (image-2). How do I fix this whole thing? Image-1 Image-2
Category: Web

Creating a new Sortable Column in WordPress Admin

I have a press release category on my WordPress site and there is too much posts being submitted and its taking up space in the All Posts and Published section of my WordPress admin, I'm wondering if there is a way to create a new sortable column where I can hide press releases category from the All Posts and Published column and make it only show in the new sortable column? Is this possible?
Category: Web

Sortable Custom Column?

I'm sorry, I speak a little English. My MySQL table: CREATE TABLE wp_visitors ( `id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY, `post_id` INT NOT NULL ); The ~/wp-content/themes/mycustomtheme/functions.php file: Add a custom column: function add_sticky_column ( $columns ) { return array_merge ( $columns, array ( 'sticky'=> 'Visitors' ) ); } add_filter ( 'manage_posts_columns' , 'add_sticky_column' ); The "Visitors" custom column values: function display_posts_stickiness ( $column, $post_id ) { if ( $column == 'sticky' ) { echo custom_counter ( $post_id ); …
Category: Web

Custom column on CPT not showing correct value when meta data not set

Basically I have 2 custom columns in the 'edit.php' of my custom post type. What I need is when $item_type is set to 'page' but there is no page selected, 'No selection' is echoed (same for when 'media' is set but there is no media file selected). What happens is it's showing the title of the post instead of the proper echo. It works fine for when the page or media file variable is set. Just when it's not set. …
Category: Web

Add taxonomy column with meta field (ACF) content

Trying to populate the column with meta field, this way (ACF): add_filter('manage_artist_custom_column', function ($content,$column_name,$term_id){ $term= get_term($term_id, 'artist'); switch ($column_name) { case 'artist_avatar': $avatar = get_field('artist_avatar', $term); var_dump($avatar); $content = $avatar['url']; break; default: break; } return $content; },10,3); add_filter( 'manage_edit-artist_columns', function ( $columns ) { $columns['artist_avatar'] = __('Artist Avatar', 'sage'); return $columns; } ); When I var_dump($avatar); I get the output: array(24) { ["ID"]=> int(315) ["id"]=> int(315) ["title"]=> string(16) "bigote-sucio-pic" ["filename"]=> string(20) "bigote-sucio-pic.jpg" ["filesize"]=> int(238431) ["url"]=> string(66) "https://futurabasura.test/app/uploads/2021/04/bigote-sucio-pic.jpg" etc … etc …
Category: Web

how to remove thumbnail and LiteSpeed Optimization column in media library list-view?

I've searched on the internet, and found out this code from this link function remove_upload_columns($defaults) { unset($defaults['comments']); unset($defaults['author']); return $defaults; } add_filter('manage_upload_columns', 'remove_upload_columns'); I put the code into functions.php child theme. It worked, now the Media Library doesn't have author column. Since I want to remove the "Uploaded to" column also, so I add this line to the code above: unset($defaults['uploaded to']); but it didn't work. The "Uploaded to" column in the Media Library still there. I've tried to change …
Category: Web

make two custom columns sortables

I have 2 custom columns, typeconsole and console: add_filter('manage_edit-post_sortable_columns', function( $columns ) { $columns['typeconsole'] = 'typeconsole'; $columns['console'] = 'console'; return $columns; }); This answer allows me to sort the first column: Make custom column sortable. When pressing the second column, the first one is ordered. How do I make them work independently?
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.