<?php | |
/** | |
* Register an action with 'fl_page_data_add_properties' hook | |
*/ | |
add_action( 'fl_page_data_add_properties', 'demo_add_properties' ); | |
function demo_add_properties(){ | |
/** | |
* Add a custom group | |
*/ | |
FLPageData::add_group( 'demo_details_group', array( | |
'label' => 'My Custom Fields' | |
) ); | |
/** | |
* Add a new property to our group | |
*/ | |
FLPageData::add_post_property( 'demo_details', array( | |
'label' => 'Address', | |
'group' => 'demo_details_group', | |
'type' => array('string'), | |
'getter' => 'demo_connection_getter', | |
) ); | |
/** | |
* A list of the meta fields | |
*/ | |
$meta_fields = array( | |
'_demo_address_1' => 'Address Line 1', | |
'_demo_address_2' => 'Address Line 2', | |
'_demo_city' => 'City', | |
'_demo_state' => 'State', | |
'_demo_zip' => 'Zip Code', | |
'_demo_country' => 'Country' | |
); | |
/** | |
* Settings option to pop up when our group is added | |
*/ | |
FLPageData::add_post_property_settings_fields( | |
'demo_details', | |
array( | |
'key' => array( | |
'type' => 'select', | |
'label' => 'Select a Field', | |
'options' => $meta_fields, | |
), | |
) | |
); | |
} | |
/** | |
* Helper function to retrieve settings fields values | |
*/ | |
function demo_connection_getter( $settings, $property ){ | |
global $post; | |
if( '' == $settings->key ) return ''; | |
return get_post_meta($post->ID, $settings->key, true); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment