Support

Account

Home Forums Backend Issues (wp-admin) Filter displayed Post Objects in Admin interface

Solved

Filter displayed Post Objects in Admin interface

  • Consider a Field Group with two Post Object selectors:

    
    $fields = array(
    	array (
    		'key' => 'field_a',
    		'label' => __('All Projects', 'foobar'),
    		'name' => 'all-projects-selector',
    		'type' => 'post_object',
    		'post_type' => 'project',
    	),
    	array (
    		'key' => 'field_b',
    		'label' => __('Parent Projects', 'foobar'),
    		'name' => 'parent-projects-selector',
    		'type' => 'post_object',
    		'post_type' => 'project',
    		'meta_query' => array( array(
    			'key' => 'post_parent',
    			'compare' => '=',
    			'value' => 0,
    		) ),
    	),
    );
    
    $args = array (
    	'key' => 'group_a',
    	'id' => 'some-fields',
    	'fields' => $fields,
    	'title' => __('Top-Level Project or Project Page selector', 'foobar'),
    );
    
    acf_add_local_field_group($args);
    

    I need the first selector to give a choice of all ‘projects’ items, and the second selector to give a choice of only those ‘project’ items which have no parent. How can I configure different filters for each field?

    I have seen the following filter, but it seems to apply to _all_ fields:
    https://www.advancedcustomfields.com/resources/acf-fields-post_object-query/

  • The issue is resolved. For future reference, the name of the filter includes the name or key of the field to which it is to be applied. In the OP example, the name of the filter would thus be:

    acf/fields/post_object/query/key=field_b

    Obviously, this makes that field’s meta_query redundant, not that it wored anyway.

Viewing 2 posts - 1 through 2 (of 2 total)

The topic ‘Filter displayed Post Objects in Admin interface’ is closed to new replies.