Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
ACF: Display custom metabox on an ACF (sub-) options page
* Add sub options page with a custom post id
if( function_exists('acf_add_options_page') ) {
'page_title' => 'CSV Sync',
'menu_title' => 'CSV Sync',
'parent_slug' => 'users.php',
'post_id' => 'aa_ucs',
'autoload' => false,
* Registers a metabox with ACF for a particular screen. You may need to find the screen ID yourself.
function aa_ucs_register_acf_metabox() {
// Verify the screen ID
if ( !acf_is_screen( 'users_page_acf-options-csv-sync' ) ) return;
// Add meta box
add_meta_box( 'meta-box-id', __( 'My Meta Box', 'textdomain' ), 'aa_ucs_display_acf_metabox', 'acf_options_page', 'normal' );
add_action( 'acf/input/admin_head', 'aa_ucs_register_acf_metabox', 10 );
* Display custom metabox on an ACF options page
function aa_ucs_display_acf_metabox() {
$text = get_option( 'example-text' );
<input type="text" name="exampletext" placeholder="Enter some example text to be saved" value="<?php echo esc_attr($text); ?>">
* Submit metabox form, save the results
* @param $post_id
function aa_ucs_save_acf_metabox_fields( $post_id ) {
if ( $post_id != 'aa_ucs' ) return;
$text = isset($_POST['exampletext']) ? stripslashes($_POST['exampletext']) : false;
update_option( 'example-text', $text );
add_action( 'acf/save_post', 'aa_ucs_save_acf_metabox_fields', 20 );

This comment has been minimized.

Copy link

alanmcginnis commented Oct 15, 2019

Thanks for this. I spent at least an hour trying to put together the right Google search and finally ended up here which is exactly what I needed.


This comment has been minimized.

Copy link
Owner Author

RadGH commented Oct 15, 2019

I'm glad it helped you out! I had the same trouble finding a solution and pieced this together based on how the ACF source code creates meta boxes. As far as I know this is the best "ACF way" to do this. Let me know if you have any suggestions for it :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.