Support

Search results for ""

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

Adjustment of options when smart filtering.

In my list page, the list table has custom field column.
Its field’s type is “post”, but the post type is custom.

When I go to the list page and do smart filtering by the custom field, its options are posts of all post type after ajax searching.
I want to filter the options by the post type that the custom field relates.
What is good way to implement this?

Thanks.

1 month, 3 weeks ago
Stefan
Developer

We don’t have a specific hook to change this.
But you can use the pre_get_posts hook and check for our request variables to change the post type for the running query. You probably want to perform some additional checks, like column name etc. But a snippet could look something like this.

add_action( 'pre_get_posts', function ( WP_Query $query ) {
	if ( filter_input( INPUT_POST, 'action' ) !== 'acp_search_comparison_request' || filter_input( INPUT_POST, 'method' ) !== 'get_options' ) {
		return;
	}

	$column_name = filter_input( INPUT_POST, 'column' );
	// Do some additional column checks

	$query->set('post_type', ['my_custom_post_type', 'extra_post_type']);
} );
1 month, 3 weeks ago
Bobby Noonan

I’m also curious on how to get this to work. I tried the code above, but I all I get is ‘No Results Found’ when I tried to filter.

4 hours, 45 minutes ago

You must be logged in to reply to this topic.