0

What is wrong with this setup? Metaboxes inside this conditional will not get saved.

// Only shows for the admin front-page assigned page.
$front_page_id = get_option( 'page_on_front' );
$post_id = (empty($_GET['post'])) ? NULL : $_GET['post'];

if (is_admin() && $front_page_id == $post_id) {
    ........
}   

Background: The idea of this setup is to have only on the static front page(Settings -> Reading) meta fields for the user to upload images that will be use on the slider.

  • There is not enough context. Where is this code? What is it hooked too? Please add more detail. – s_ha_dum Sep 14 '13 at 16:39
  • The code is on functions.php. You can put any metabox inside the if conditional and it will not work. – Daniel Sep 14 '13 at 16:56
  • how do you sending data? If you sending data from backend edit page then your should use $_POST or $_REQUEST – Sisir Sep 14 '13 at 17:18
  • An answer was given and it not solves the issue for the lack of details already asked for... – brasofilo Sep 14 '13 at 17:25
2

You have to use $_REQUEST instead of $_GET, because when an user saves a post the POST request will be send to the server. It means that there is no $_GET['post'] argument and your meta boxes won't be registered. And if they are not registered, then nothing will be saved.

// Only shows for the admin front-page assigned page.
$front_page_id = get_option( 'page_on_front' );
$post_id = (empty($_REQUEST['post'])) ? NULL : $_REQUEST['post'];

if (is_admin() && $front_page_id == $post_id) {
    ........
} 

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.