Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
Quentin Véron

ACF – Hook Object Post


I’m using ACF and I’ve an Object Post named fiche-featured.

I’m filtering the results from this field using the acf/fields/post_object/query/ hook from ACF.

function gpc_acf_fiche_featured( $args, $field, $post_id ) {
	$args['meta_key']     = 'fiche-attachment';
	$args['meta_value']   = $post_id;
	$args['meta_compare'] = '=';

	return $args;

add_filter( 'acf/fields/post_object/query/name=theme-featured', 'gpc_acf_fiche_featured', 10, 3 );

This work great but I’d like to apply this filtering is bulk editing too.
Is there any hook from Admin Columns I could use to do such thing?

Thank you.

4 years, 8 months ago
Stefan van den Dungen Gronovius


We don’t have a specific hook to alter the query for editing.
But since we use WP_Query for most searched in Editing, you should be able to use the pre_get_posts hook to alter the query. The problem with that for your use case is that your code needs an ID to work with and we don’t send an ID to the Ajax request at this moment. I already changed this in our code for the next release.

So if you want to work on that, you’ll only have to right conditionals for the hook to fire. Since this call is done on an Ajax call, you can check the params to do that. The snippet would look something like this.

add_action( 'pre_get_posts', function ( WP_Query $query ) {
	if (
		filter_input( INPUT_GET, 'action' ) === 'acp_editing_single_request' &&
		filter_input( INPUT_GET, 'method' ) === 'get_select_values' &&
		filter_input( INPUT_GET, 'column' ) === 'column_name'

	) {
		$mq = (array) $query->get( 'meta_query' );
		$mq[] = [
			'key'     => 'fiche-attachment',
			'value'   => filter_input( INPUT_GET, 'item_id' ),
			'compare' => 'like',

		$query->set( 'meta_query', $mq );
} );

Please remember that this currently does not work since the item_id is not sent at this moment.
You’ll also have to check for the right column that is initiating the call. You can check that by the name.

4 years, 8 months ago

You must be logged in to reply to this topic.