Skip to content

Instantly share code, notes, and snippets.

@egrouse
Created July 3, 2012 14:29
Show Gist options
  • Save egrouse/3040051 to your computer and use it in GitHub Desktop.
Save egrouse/3040051 to your computer and use it in GitHub Desktop.
WordPress meta issues
// Custom meta boxes for the homepage signs
add_action( 'add_meta_boxes', 'r6_add_sign_box' ); // Create meta box action
add_action( 'save_post', 'r6_save_postdata' ); // Save data for meta box
function r6_add_sign_box()
{
add_meta_box(
'r6_sign_meta',
'Homepage Signs',
'r6_draw_sign_box',
'page'
);
}
function r6_draw_sign_box( $post )
{
// Output nonce
wp_nonce_field();
// Set number of available signs
$signCount = 10;
// Iterate
for( $i = 1; $i <= $signCount; $i++ )
{
echo '<h4>Sign ' . $i . '</h4>';
echo '<label for="sign' . $i . 'title">Title: </label><input type="text" name="sign' . $i . 'title" /><br />';
echo '<label for="sign' . $i . 'text">Text: </label><input type="text" name="sign' . $i . 'text" /><br />';
echo '<label for="sign' . $i . 'link">Link: </label><input type="text" name="sign' . $i . 'link " /><br />';
echo '<label for="sign' . $i . 'image">Image: </label><input id="sign' . $i . 'image" type="text" size="36" name="sign' . $i . 'image" value="" />';
echo '<input id="sign' . $i . 'image_button" type="button" value="Upload Image" /> (should be 117x60)';
echo '<script type="text/javascript">
jQuery( document ).ready( function(){
jQuery( "#sign' . $i .'image_button" ).click( function(){
formfield = jQuery( "#sign' . $i .'image" ).attr( "name" );
tb_show( "", "media-upload.php?type=image&TB_iframe=true" );
return false;
});
window.send_to_editor = function( html ){
imgurl = jQuery( "img", html ).attr( "src" );
jQuery( "#" + formfield ).val( imgurl );
tb_remove();
};
});
</script>';
}
return;
}
function r6_save_postdata( $post_id )
{
// Fail if this is an autosave
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// Check for nonce
if( !wp_verify_nonce( $_POST['_wpnonce'] ) )
return;
print_r( $_POST );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment