Skip to content

Instantly share code, notes, and snippets.

@BhargavBhandari90
Created December 14, 2021 18:34
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 BhargavBhandari90/1608cfecc56a4db3a966c03a900f851d to your computer and use it in GitHub Desktop.
Save BhargavBhandari90/1608cfecc56a4db3a966c03a900f851d to your computer and use it in GitHub Desktop.
ACF get custom setting.
<?php
/**
* Get custom settings. This works for group type field only.
*
* @param string $tab
* @param string $field
*
* @return void
*/
function acf_get_custom_setting( $tab, $field ) {
// Prevent unnecessary function execution.
if ( ! function_exists( 'have_rows' ) || empty( $field ) || empty( $tab ) ) {
return;
}
$value = '';
// Get field value.
if ( have_rows( $tab, 'option' ) ) {
while ( have_rows( $tab, 'option' ) ) {
the_row();
$value = get_sub_field( $field );
}
}
return $value;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment