1

I've created a custom menu page with some fields. I want to store these settings to use elsewhere.

The form with the fields should save and POST data using action="options.php" but every time I hit save on the form it sends me back to the settings page, and does not save the data.

I'm registering the settings in my functions.php

function register_settings() {  
        register_setting('settings-group','phonenumber');
        register_setting('settings-group','primaryemail');
        register_setting('settings-group','secondemail');
    }

This is the form action

<form method="post" action="options.php">

Here is the full code which is in functions.php http://pastebin.com/zVhSLZ9d

1 Answer 1

5

Add

<?php settings_fields( 'settings-group' ); ?>
<?php do_settings_sections( 'settings-group' ); ?> 

immediately after the <form> tag

Your code is registering the settings group, setting up the DB to store the information, but it is/was missing the callback to allow WordPress to actually act on that information or store it.

The code I provided tells WordPress what to access, and what to do with the form.

2
  • 1
    Please explain why Sep 3, 2014 at 15:12
  • @PieterGoosen I fully intended to, but the mobile app cut me off for some reason - Explanation now added - thanks for the reminder!
    – Scott S
    Sep 4, 2014 at 16:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.