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.

3 years, 4 months ago
Stefan van den Dungen Gronovius
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']);
} );
3 years, 4 months 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.

3 years, 2 months ago
Stefan van den Dungen Gronovius
Developer

@Bobby,
Just to be sure, did you change the post types I used in my example?
If so, can you send me the exact snippet that you used for your use case?
Based on your previous support questions, I know that you’re using ACF, so is there a reason why you don’t use the ACF column from our integration?

3 years, 2 months ago

You must be logged in to reply to this topic.