Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the community forum?
All Topics
Christopher

Post Template Column and Filter

We’re using a few post templates (image, video) that we created, but we expect the default template to be considered the “Article” template (the filter default_page_template_title allows us to change the metabox option from “Default Template” to whatever we want, in this case “Article”).

But in Admin Columns Pro, we can add a column and filter for post/page templates, but any posts using the default template simply show a “-” in the column instead of “default” or our custom template title. And the filter shows “default” as the option for filtering by default templates.

Is there a way to update both the template name in the column and in the filter dropdown?

Possibly relevant code in WP core: https://github.com/WordPress/WordPress/commit/7cdbac53e8497b346d1009375d36586fb6e5197c

2 months, 2 weeks ago
Stefan
Developer

I understand the use case, and I have two snippets for you that will change the title in the overview and in the filter drop down. I’m not sure if this is something that we will change in our code, although I believe the the default title can at least use the default WordPress title instead of ‘default’. I’ll make an issue and decide later if we’re going to change it in our code. Here’s the code that will probably work immediately on your environment if you don’t have any conditionals in your hook.

/**
 * @param           $value
 * @param int       $id
 * @param AC\Column $column
 */
function acp_column_value_default_template_name( $value, $id, $column ) {
	if ( $column instanceof AC\Column\Post\PageTemplate ) {
		if ( $value === $column->get_empty_char() ) {
			$value = apply_filters( 'default_page_template_title', $column->get_empty_char(), 'ac-column-value' );
		}
	}
	return $value;
}

add_filter( 'ac/column/value', 'acp_column_value_default_template_name', 10, 3 );

/**
 * @param array     $args
 * @param AC\Column $column
 */
function acp_filtering_options_default_page_template( $args, $column ) {

	if ( $column instanceof ACP\Column\Post\PageTemplate ) {
		if ( isset( $args['options']['default'] ) ) {
			$args['options']['default'] = apply_filters( 'default_page_template_title', __( 'Default Template' ), 'ac-filter-option' );
		}
	}
	return $args;
}
add_filter( 'acp/filtering/dropdown_args', 'acp_filtering_options_default_page_template', 10, 2 );
2 months, 2 weeks ago
Christopher

This works perfectly. Thanks so much.

2 months, 1 week ago

You must be logged in to reply to this topic.