Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Shawn

Add filtering for Custom Column

The starter kit for the custom column is awesome, but I dont see where I can enable filtering for the column.

Here’s my situation, that I was trying to solve with a custom column.

I have a custom post type that is a child of a another post type. All of the children post types have a custom field that stores the parent’s post id. Obviously I can easily display that using a custom field and enable filtering using your GUI. But, the issue is that displaying the parent post id instead of the parent post title isnt user friendly. So I thought I could get around this by creating a custom column that will display the title instead. That was easy enough, but now I cant filter it.

I really dont care how this is accomplished. Either using your built in Custom Field, but filtering the output to display the title…. or …. adding filtering support for a custom column.

Thanks!

6 years, 1 month ago
Tobias
Developer

Hi Shawn,

Did you try setting the output of the Custom Field column to “Post Title”? This should display all post titles instead of their ID’s.

Tobias

6 years, 1 month ago
Shawn

The list I’m trying to add the field to is the Chapters list. If I set it to Post Title, it will display the title of the chapter. I want it to display the title of the parent post which is a Story. The post title for the story isnt held in the chapter post meta, only the ID.

Basically, I want to be able to filter the chapter list by the story it belongs to by the story title, not the ID.

Using a custom field:
Result:

Using a custom column:

6 years, 1 month ago
Tobias
Developer

What I meant was setting the “Field Type” of the “Custom Field column” to “Post Title (Post Id’s)”. It seems that’s what you are looking for.

If that’s not sufficient you could also use this filter: cac-addon-filtering-options. It will allow you to change the labels of the filter menu from an ID to Title.

Here is an example that should work for your Chapters:


function my_cac_filtering_options_change_label_to_title( $options, $column ) {
	$custom_field = '_wpcf_belong_stories_id'; // enter your custom field key

	if ( 'column-meta' == $column->get_type() && $custom_field == $column->get_field() ) {
		foreach ( $options as $value => $label ) {
			$options[ $value ] = get_the_title( $value );
		}
	}
	return $options;
}
add_filter( 'cac/addon/filtering/options', 'my_cac_filtering_options_change_label_to_title', 10, 2 );
6 years, 1 month ago
Tobias
Developer

We haven’t yet built-in the right methods to use filtering inside your own created column type. It’s something we have to work out a bit more, as filtering queries are quite complex, and we want to keep it simple for our users and developers :)

6 years, 1 month ago
Shawn

Ugh. I’m an idiot. I didnt understand what you meant. Your first suggestion totally works. No need for custom code. I’m so sorry to have wasted your time. Thank you.

6 years, 1 month ago
Tobias
Developer

No worries, glad I could help =)

6 years, 1 month ago

You must be logged in to reply to this topic.