Skip to content

Instantly share code, notes, and snippets.

@wpeasy
Created September 17, 2023 00:14
Show Gist options
  • Save wpeasy/c0b7da40549c98ba50ffc0ea0cd8ffee to your computer and use it in GitHub Desktop.
Save wpeasy/c0b7da40549c98ba50ffc0ea0cd8ffee to your computer and use it in GitHub Desktop.
& Metabox Automagical Data Atts
<?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