Skip to content

Instantly share code, notes, and snippets.

@mishterk
Last active November 2, 2021 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mishterk/509b0048650775f2c40fcc81e3a16255 to your computer and use it in GitHub Desktop.
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/
<?php
advanced_form( 'form_61806dc10891f', [
'exclude_fields' => [
'field_61806e15ca267',
'email',
]
] );
<?php
advanced_form( 'form_61806dc10891f', [
'exclude_fields' => [ 'field_61806e15ca267' ]
] );
<?php
advanced_form( 'form_61806dc10891f', [
'exclude_fields' => [ 'customer_id' ]
] );
<?php
add_filter( 'af/form/args/key=form_61806dc10891f', function ( $args, $form ) {
$args['exclude_fields'] = [
'field_61806e15ca267',
'email',
];
return $args;
}, 10, 2 );
<?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