$15
Using Metabox with scheduled post, meta box doesn't display :(
/* Meta Boxes */
add_action( 'add_meta_boxes', 'es_metabox_post_ads_create' );
function es_metabox_post_ads_create()
{
//create a custom meta box
add_meta_box( 'es_metabox_post_ads', 'Post Ads', 'es_metabox_post_ads_function', 'post', 'side', 'low' );
}
function es_metabox_post_ads_function( $post )
{
$eirepanel_inline_ads_options = get_option('eirepanel_inline_ads_options');
$select_post_ads = get_post_meta( $post->ID, '_select_post_ads', true ); ?>
<select name="select_post_ads">
<option style="min-width: 120px;">Please Select</option>
<?php for($i=0; $i<count($eirepanel_inline_ads_options['eirepanel_inline_ads_options_name']); $i++): ?>
<?php
$selected = '';
if($select_post_ads == $eirepanel_inline_ads_options['eirepanel_inline_ads_options_name'][$i])
{
echo $selected = 'selected';
echo $eirepanel_inline_ads_options['eirepanel_inline_ads_options_name'][$i];
}
sort($eirepanel_inline_ads_options['eirepanel_inline_ads_options_name']); ?>
<option style="min-width: 120px;" <?php echo $selected; ?> >
<?php echo $eirepanel_inline_ads_options['eirepanel_inline_ads_options_name'][$i]; ?>
</option>
<?php endfor; ?>
</select>
<?php
}
//hook to save the meta box data
add_action( 'save_post', 'boj_mbe_save_post_ads_meta' );
function boj_mbe_save_post_ads_meta( $post_id )
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
update_post_meta( $post_id, '_select_post_ads', strip_tags( $_POST['select_post_ads'] ) );
}
Keith Donegan | 07/04/11 at 8:57am
| Edit
Previous versions of this question:
07/04/11 at 9:18am
| 07/04/11 at 9:23am
(3) Possible Answers Submitted...
-

Last edited:
07/04/11
9:16amUtkarsh Kukreti says:Please post the code you're using.
- 07/04/11 9:18am
Keith Donegan says:Hey, is this enough?
- 07/04/11 9:20am
Utkarsh Kukreti says:There must be some more code. Something that contains 'add_post_meta'.
- 07/04/11 9:23am
Keith Donegan says:Sorry, missed that block, updated.
- 07/04/11 9:18am
-

Last edited:
07/04/11
9:19amArmando Jaleo says:Hi Keith:
Please Do you can give me more information, I don't understand "(but if you go back into the post and click update, the ad then appears)"
You can check: to save and publish a post straight away and edit and change the date of publish.
Greetings!- 07/04/11 9:22am
Keith Donegan says:Hi Armando.
I can indeed save and publish the post and the ad appears, but my client has alot of authors that need to schedule posts and have then displayed over time.
- 07/04/11 9:22am
-

Last edited:
07/04/11
9:47amJurre Hanema says:I believe the save_post action is also called when a post status transitions from scheduled to published. Because in that case $_POST is of course empty the metadata gets removed.
So I have a feeling a simple check before you update the post metadata like this may solve the issue:
function boj_mbe_save_post_ads_meta( $post_id )
{
if ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
return $post_id;
if(isset($_POST['select_post_ads']))
update_post_meta($post_id, '_select_post_ads', strip_tags( $_POST['select_post_ads'] ) );
}
- 07/04/11 10:09am
Keith Donegan says:Bingo, that makes sense! Thank you
- 07/04/11 10:16am
Keith Donegan says:How do I pay you? lol
- 07/04/11 10:23am
Jurre Hanema says:I believe you should use the "Vote?"-link underneath your first post.
- 07/04/11 10:32am
Keith Donegan says:Done, get it ok?
- 07/04/11 10:09am
This question has expired.
Keith Donegan voted on this question.
Current status of this question: Completed




