0

I have two option pages: General Options > MyOptionPage1 and CustomPostType > MyOptionPage2

Both have a form, but the after clicking Save in second option page I land in the 404 page.

Here is my code (file customposttype-options.php included in my plugin) :

<?php
function customposttype_options_menu()
{
    add_submenu_page( "edit.php?post_type=customposttype", "Impostazioni customposttype", "Impostazioni customposttype", "manage_options", "impostazioni_customposttype_page", 'customposttype_options');
}
function customposttype_options()
{
    ?>
    <div class="wrap">
        <h2>Impostazioni customposttype</h2>

        <form method="post" action="customposttype-options.php">
            <?php settings_fields( 'impostazioni_customposttype' ); ?>
            <?php do_settings_sections( 'impostazioni_customposttype' ); ?>



            <label for="colore_sfondo">Colore sfondo</label>
            <input type="text" id="colore_sfondo" name="colore_sfondo" value="<?php echo esc_attr( get_option('colore_sfondo') ); ?>">

            <?php submit_button(); ?>
        </form>
    </div>
    <?php
}

function register_customposttype_options() { // whitelist options
    register_setting("impostazioni_customposttype", "colore_sfondo");
}

add_action( 'admin_menu', 'customposttype_options_menu' );
add_action( 'admin_menu', 'register_customposttype_options');

I've tried to change the action attribute of the form but nothing changed (action="", no action, admin_url('customposttype-options.php'), ...). The first working option page is exactly the same but with namespace changed (so, settings_fields( 'impostazioni_generaloptions' );).

  • action should definitely not be customposttype-options.php ... action="" or no action should work as it posts back to the same page that way. what is the address bar URL of the page. you could try using that... – majick Apr 25 '16 at 13:28
2

Did you try just using option.php?

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

  • Your solution saves the data, but Wordpress doesn't show me Options saved successfully . Any idea? – Mattia Merlini Apr 25 '16 at 13:12
  • 1
    Try <?php settings_errors( 'impostazioni_customposttype' ) ?> right after your <h2> – TheDeadMedic Apr 25 '16 at 13:25
  • It doesn't show me Options saved successfully but it's a good practice insert that line. – Mattia Merlini Apr 25 '16 at 20:46
  • 1
    I found this from -wordpress.org/support/topic/… <?php if( isset($_GET['settings-updated']) ) { ?> <div id="message" class="updated"> <p><strong><?php _e('Settings saved.') ?></strong></p> </div> <?php } ?> – Gregory Schultz Apr 25 '16 at 21:23
  • 1
    @GregorySchultz I edited your answer, when you accept the edit I'll mark it as accepted. – Mattia Merlini Apr 26 '16 at 21:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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