Support

Account

Home Forums Front-end Issues Change value when regsitering field via php based upon taxonomy selected

Helping

Change value when regsitering field via php based upon taxonomy selected

  • I”m registering a field via php and I was wondering is it possible to change a value in one of the filters based upon a taxonomy selected.

    If you take a look at the filed under the taxonomy I have it filtering the options by the hero taxonomy but would like to be able to change the hero-1 based upon which hero the author selects in the hero taxonomy.

    So for example if I select hero-3 in the taxonomy when writing the post it would just show me talents that are belong to the hero-3 taxonomy. So pretty much I need the taxonomy filter to be dynamic based upon which taxonomy term is selected.

    array (
    			'key' => 'field_5578a91421158',
    			'label' => 'Build Tier 3',
    			'name' => 'build_tier_3',
    			'type' => 'post_object',
    			'instructions' => '',
    			'required' => 0,
    			'conditional_logic' => 0,
    			'wrapper' => array (
    				'width' => '',
    				'class' => '',
    				'id' => '',
    			),
    			'post_type' => array (
    				0 => 'talent',
    			),
    			'taxonomy' => array (
    				0 => 'hero:hero-1',
    			),
    			'allow_null' => 0,
    			'multiple' => 0,
    			'return_format' => 'object',
    			'ui' => 1,
    		),
  • Hi Greenhoe,

    I don’t think you can easily update the taxonomy parameter of your field once the edit screen has been rendered. It would require an AJAX call and recreating the entire field dynamically..

    May I suggest a different solution that’s maybe a bit easier and doable.
    If you use a relationship field instead there’s a built in filter capability for taxonomies. You can set the field to only allow for 1 value so that it’ll work pretty much the same as the post_object field.

    Then if you really want you should be able to create some custom Javascript for the extra functionality. Look for a change in the taxonomy dropdown and change the taxonomy filter dropdown in the relationship field accordingly. It should trigger the filtering automatically. If you also want to make sure the client can’t change the filter themselves you could just add a tiny CSS snippet to hide the taxonomy filter from them.

    What do you think?

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

The topic ‘Change value when regsitering field via php based upon taxonomy selected’ is closed to new replies.