Home › Forums › Front-end Issues › exclude field on fields array
Hello,
I use this code that I found on the forum to display all my custom fields of group 30109
However I would like to know if I can exclude custom fields?
Example I would like to display everything except
– amount
– type
– model
Here is the code
<?php
$group_ID = 30109;
$fields = array();
$fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
if( $fields )
{
echo '<div class="col-sm-6">';
echo '<h3>Description:</h3>';
echo '<ul class="list-unstyled">';
foreach( $fields as $field_name => $field )
{
$value = get_field( $field['name'] );
if ($field['choices']){
$map = array(
'yes' => '<i class="icon-ok"></i>'
);
$value = $map[ $value ];
} else {
}
if( $value && $value != 'no') {
echo '<li>' . $field['label'] . ' ' . $value . '</li>';
}
}
echo '</ul>';
echo '</div>';
}
?>
Thank you
Hello,
Is it possible to exclude with my code present at the top?
thank you
You would need to check them against something, like an array of field keys, for example:
// list of field keys to not show
$exclude = array('field_123', 'field_234', 'field_456');
// your loop
foreach( $fields as $field_name => $field ) {
if (in_array($field['key'], $exclude) {
// one of the fields to exclude
// skip it
continue;
}
// ..... the rest of your loop here ....
Hello and thank you for your answer,
I tried this but I think I did wrong the code,
Can you see when you have time?
thank you
<?php
$group_ID = 30109;
$fields = array();
$fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
$exclude = array('field_5919f45752917', 'field_5919f46252918', 'field_5919f46a52919');
if( $fields )
{
echo '<div class="col-sm-6">';
echo '<h3>Description:</h3>';
echo '<ul class="list-unstyled">';
foreach( $fields as $field_name => $field ) {
if (in_array($field['key'], $exclude) {
{
$value = get_field( $field['name'] );
if ($field['choices']){
$map = array(
'yes' => '<i class="icon-ok"></i>'
);
$value = $map[ $value ];
} else {
}
if( $value && $value != 'no') {
echo '<li>' . $field['label'] . ' ' . $value . '</li>';
}
continue;
}
}
echo '</ul>';
echo '</div>';
}
?>
<?php
$group_ID = 30109;
$fields = array();
$fields = apply_filters('acf/field_group/get_fields', $fields, $group_ID);
$exclude = array('field_5919f45752917', 'field_5919f46252918', 'field_5919f46a52919');
if ($fields) {
echo '<div class="col-sm-6">';
echo '<h3>Description:</h3>';
echo '<ul class="list-unstyled">';
foreach ($fields as $field_name => $field) {
if (in_array($field['key'], $exclude)) {
continue;
}
$value = get_field( $field['name'] );
if ($field['choices']){
$map = array(
'yes' => '<i class="icon-ok"></i>'
);
$value = $map[ $value ];
} else {
}
if ( $value && $value != 'no') {
echo '<li>' . $field['label'] . ' ' . $value . '</li>';
}
} // end foreach
echo '</ul>';
echo '</div>';
} // end if fields
?>
Thank you very much for your help,
it works very well now :-),
good evening
The topic ‘exclude field on fields array’ is closed to new replies.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.