Last active
November 2, 2021 00:06
-
-
Save mishterk/509b0048650775f2c40fcc81e3a16255 to your computer and use it in GitHub Desktop.
How to exclude fields from rendering in ACF front end forms when using Advanced Forms Pro. Code snippets accompany the post: https://hookturn.io/2021/11/exclude-fields-in-acf-front-end-forms/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
advanced_form( 'form_61806dc10891f', [ | |
'exclude_fields' => [ | |
'field_61806e15ca267', | |
'email', | |
] | |
] ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
advanced_form( 'form_61806dc10891f', [ | |
'exclude_fields' => [ 'field_61806e15ca267' ] | |
] ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
advanced_form( 'form_61806dc10891f', [ | |
'exclude_fields' => [ 'customer_id' ] | |
] ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'af/form/args/key=form_61806dc10891f', function ( $args, $form ) { | |
$args['exclude_fields'] = [ | |
'field_61806e15ca267', | |
'email', | |
]; | |
return $args; | |
}, 10, 2 ); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
add_filter( 'af/form/args/key=form_61806dc10891f', function ( $args, $form ) { | |
// If the URL query string does not contain the `show_customer_id` parameter with a | |
// non-empty value, hide the `customer_id` field. | |
if ( empty( $_GET['show_customer_id'] ) ) { | |
$args['exclude_fields'] = [ 'customer_id' ]; | |
} | |
return $args; | |
}, 10, 2 ); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment