Created
September 17, 2023 00:14
-
-
Save wpeasy/c0b7da40549c98ba50ffc0ea0cd8ffee to your computer and use it in GitHub Desktop.
& Metabox Automagical Data Atts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* | |
In Bricks Attributes -> Name - insert {echo:mb_data_atts} | |
Don't put anything in the Value field | |
*/ | |
function mb_data_atts(){ | |
$fields = get_post_meta(get_the_ID()); | |
$out = ""; | |
foreach($fields as $key=>$value){ | |
if(str_starts_with($key, 'data_' )){ | |
$data_name = str_replace('_', '-', $key); | |
/* MetaBox stores the single values as an array */ | |
$actual_value = $value[0]; | |
$out.= $data_name . '="' . $actual_value . '" '; | |
} | |
} | |
return $out ; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment