Hi there,
This is the first time I've posted in the WordPress forum. I've used wordpress for a while now and have recently ventured into creating my own custom post types and custom meta so I can have more control and not have to rely so heavily on plugins.
I've managed to set up some custom post meta which has been working fine in my local environment. The idea is the user can add more than one meta box called "slides" and add data to each slide.
The problem occurred when I moved my site to a test server to start adding content etc. The custom post meta still works as expected however the content I added in the local environment will not display. It is in the database but will not come through. Any data I put in to the 'slides' overwrites the old content and then works as expected.
I need to sort this now otherwise when it come to going live I will have a lot of content to add in all over again, losing about 3 days of work!
Here are the main highlights of the code.
add_meta_box (fairly standard):
function dynamic_add_custom_box() {
add_meta_box('slide_content', __( 'Scrolling Page', 'scrolling_pages' ), 'slide_content_custom_box');
}
add_action( 'add_meta_boxes', 'dynamic_add_custom_box' );
The main function to pull the data into the page editor (slightly simplified!):
function slide_content_custom_box() {
global $post;
wp_nonce_field( plugin_basename( __FILE__ ), 'dynamicMeta_noncename' );
?>
<div id="meta_inner">
<?php
$slide_content = get_post_meta($post->ID,'slide_content',true);
$c = 0;
foreach( $slide_content as $content ) {
if ( isset( $content['image'] ) || isset( $content['text'] ) ) {
echo '<div class="slide"><h2>' . ($c+1) . '. ' . $content['title'] . '</h2><a class="sort">|||</a>
<div class="slideContent">
<label for="meta-title" class="prfx-row-title">Slide Title</label>
<span class="inputWrap">
<input type="text" name="slide_content[' . $c . '][title]" class="text_multiple_title' . $c . '" value="' . $content['title'] . '" />
</span>
</div></div>';
$c = $c +1;
}
}
?>
<span id="here"></span>
<span class="add"><?php _e('Add Slide'); ?></span>
<script type="text/javascript">
var $ =jQuery.noConflict();
$(document).ready(function() {
$('.slideContent').hide();
var count = <?php echo $c; ?>;
$(".add").click(function() {
slide = count + 2;
$('#here').append('<div class="slide"><h2>' . ($c+1) . '. ' . $content['title'] . '</h2><a class="sort">|||</a><div class="slideContent"><label for="meta-title" class="prfx-row-title">Slide Title</label><span class="inputWrap"><input type="text" name="slide_content[' . $c . '][title]" class="text_multiple_title' . $c . '" value="' . $content['title'] . '" /></span></div></div>' );
count++;
return false;
});
$(".remove").live('click', function() {
$(this).closest('.slide').remove();
});
});
</script>
</div>
<?php
}
Saving the data:
function dynamic_save_postdata( $post_id ) {
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
if ( !isset( $_POST['dynamicMeta_noncename'] ) )
return;
if ( !wp_verify_nonce( $_POST['dynamicMeta_noncename'], plugin_basename( __FILE__ ) ) )
return;
$slide_content = $_POST['slide_content'];
if ($slide_content != "") {
update_post_meta($post_id,'slide_content',$slide_content);
}
}
I've been banging my head against a brick wall for a few hours now. Could it be something to do with the Nonce?
Any help would be appreciated.