Home › Forums › Feedback › Directly get a layout by its ID › Reply To: Directly get a layout by its ID
function taz_get_field_data($shortcodeID){
if (class_exists('acf')){
$layouts = get_field('taz_shortcodes');
return $layouts[$shortcodeID - 1];
} else {
error_log("ACF Plugin is not available.");
return null;
}
}
function taz_shortcode($atts, $content = null){
$a = shortcode_atts(array(
'id' => null
), $atts);
$shortcodeID = (int)$a['id'];
$rowData = taz_get_field_data($shortcodeID);
switch ($rowData['acf_fc_layout']){
case 'gallery': // your layout name
// Do you stuff
break;
case 'before_after':
// Do you stuff
break;
case 'rewind_forward':
// Do you stuff
break;
default:
break;
}
}
add_shortcode('taz_shortcode', 'taz_shortcode');
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.