-
-
Save kucrut/3804376 to your computer and use it in GitHub Desktop.
Great Tutorial ....
How do i get the custom filed value?
Is this right way?
$a = get_post_meta($item->object_id,'custom_field',true);
or any other ..?
Hmm. This didn't work for me either. Is there any other sources online about adding new input fields to the wordpress menu editor?
how to get additional fileds value bro ?
For anyone else coming here wondering how to get the value:
You need to prepend your field name with "_menu_item". So if you have a field name "anchor":
get_post_meta($item->ID, '_menu_item_anchor', true)
Would you be able to help me figure out how to make this work for a checkbox? Also a trimmed down version for a single field would be awesome (but I can probably figure that out on my own).
For anyone who wonders how to use on the frontend:
add_filter( 'nav_menu_link_attributes', 'my_nav_menu_attribs', 10, 3 );
function my_nav_menu_attribs( $atts, $item, $args ) {
$atts['data-mydata'] = get_post_meta($item->ID, '_menu_item_mydata', true);
return $atts;
}
@kucrut, thanks for sharing!
Does anyone know how to display the additional fields in the menu editor inside Customizer?
@JacobDB: Did you get the checkbox to work? I've managed to convert the fields, but haven't yet been succesful in saving (and retrieving) them to/from the database.
If anyone here - how to add checkbox and/or select input ?
if anyone gets to here, this is now packaged into a library that you can use
How to do when there's two or more fields 'item_tpl', 'item_tpl2', 'item_tpl3'
I got an error when I do this code below.
$new_fields .= str_replace(
array_map(function($key){ return '{' . $key . '}'; }, array_keys($field)),
array_values(array_map('esc_attr', $field)),
self::$options['item_tpl', 'item_tpl2', 'item_tpl3']
);
Please help Thanks!
Hi friends,how to add checkbox and/or select input ?
and how to get values ??
@kucrut great use of filters for providing the additional fields.