Support

Account

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');