رفتن به مطلب

ذخیره نشدن متاباکس


پست های پیشنهاد شده

سلام

من این متاباکس رو ایجاد کردم

ولی بعد از انتشار ذخیره نمیشه

لطفا کمک کنید


function prfx_custom_meta() {
add_meta_box( 'prfx_meta', __( 'انتخاب پست', 'prfx-textdomain' ), 'prfx_meta_callback', 'page_news_letter','advanced','high' );
}
add_action( 'add_meta_boxes', 'prfx_custom_meta' );


# Outputs the content of the meta box
function prfx_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'prfx_nonce' );
$prfx_stored_meta = get_post_meta( $post->ID );
?>
<p>
<?php
$my_custom_query= new WP_Query(array(
'post_type' => 'post',
'post_status' => 'publish',
'cat' => '1',
'order' => 'DESC',
'orderby' => 'ID',
'posts_per_page' =>'10',
'paged' => (get_query_var('paged')) ? get_query_var('paged') : 1
)); ?>
<?php
if($my_custom_query->have_posts()) : ?>
<table>
<th>اخبار تولیدات</th>
<tr>
<td>خبر اول</td>
<td>
<select name="news-one" id="news-one">
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php if ( isset ( $prfx_stored_meta['news-one'] ) ) echo $prfx_stored_meta['news-one'][0]; ?>">
<?php the_title(); ?>
</option>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</select>
</td>
</tr>
<tr>
<td>خبر دوم</td>
<td>
<select name="news-two">
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php if ( isset ( $prfx_stored_meta['news-one'] ) ) echo $prfx_stored_meta['news-one'][0]; ?>">
<?php the_title(); ?>
</option>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</select>
</td>
</tr>
<tr>
<td>خبر سوم</td>
<td>
<select name="news-three">
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php if ( isset ( $prfx_stored_meta['news-two'] ) ) echo $prfx_stored_meta['news-two'][0]; ?>">
<?php the_title(); ?>
</option>
<?php endwhile; ?>
<?php wp_reset_query(); ?>
</select>
</td>
</tr>
<tr>
<td>خبر چهارم</td>
<td>
<select name="news-four">
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php if ( isset ( $prfx_stored_meta['news-three'] ) ) echo $prfx_stored_meta['news-three'][0]; ?>">
<?php the_title(); ?>
</option>
<?php endwhile; ?>
</select>
</td>
</tr>
</table>
<?php endif; ?>
<?php wp_reset_query(); ?>


function prfx_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'prfx_nonce' ] ) && wp_verify_nonce( $_POST[ 'prfx_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'news-one' ] ) ) {
update_post_meta( $post_id, 'news-one', sanitize_text_field( $_POST[ 'news-one' ] ) );
}
if( isset( $_POST[ 'news-two' ] ) ) {
update_post_meta( $post_id, 'news-two', sanitize_text_field( $_POST[ 'news-two' ] ) );
}
if( isset( $_POST[ 'news-three' ] ) ) {
update_post_meta( $post_id, 'news-three', sanitize_text_field( $_POST[ 'news-three' ] ) );
}
}
add_action( 'save_post', 'prfx_meta_save' );

لینک به ارسال

خوب توی متاباکس که چیزی ندارید

اصلا فرمی نیست که اطلاعاتی فرستاده بشه

برای همین چیزی ذخیره نمیشه!

لینک به ارسال

خوب توی متاباکس که چیزی ندارید

اصلا فرمی نیست که اطلاعاتی فرستاده بشه

برای همین چیزی ذخیره نمیشه!

ینی چی؟

من االان چهارتا لیست آبشاری میبینم که تو همشون هم پست های دیگه رو نمایش میده

لینک به ارسال

درستش کردم:


/*Adding Meta Boxes to Any Posts*/
add_action( 'add_meta_boxes', 'adding_meta_box' );
function adding_meta_box()
{
add_meta_box( 'meta_box_id', 'اطلاعات پست', 'frst_meta_box', 'page_news_letter', 'normal', 'high' );
}
function frst_meta_box( $post )
{
$value = get_post_custom( $post->ID );
/* tolidat */
$news_one_text = isset( $value['news_one'] ) ? esc_attr( $value['news_one'][0] ) : '';
$news_two_text = isset( $value['news_two'] ) ? esc_attr( $value['news_two'][0] ) : '';
$news_three_text = isset( $value['news_three'] ) ? esc_attr( $value['news_three'][0] ) : '';
$news_four_text = isset( $value['news_four'] ) ? esc_attr( $value['news_four'][0] ) : '';
$text_field_three = isset( $value['meta_box_text_field_three'] ) ? esc_attr( $value['meta_box_text_field_three'][0] ) : '';
wp_nonce_field( 'my_meta_box_nonce', 'meta_box_nonce' );?>
<?php $my_custom_query= new WP_Query(array(
'post_type'=>'post','post_status'=>'publish','cat'=>'1','order'=>'DESC','orderby'=>'ID',
'posts_per_page'=>'10','paged'=>(get_query_var('paged')) ? get_query_var('paged') : 1 )); ?>
<?php if($my_custom_query->have_posts()) : ?>
<table>
<th>اخبار تولیدات</th>
<tr>
<td>خبر اول</td>
<td>
<select name="news_one" id="news_one" style="width: 250px;">
<option value="<?php echo $news_one_text; ?>" selected><?php echo $news_one_text; ?></option>
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php the_title(); ?>"><?php the_title(); ?></option>
<?php endwhile; ?>
</td>
<td>
<input size="65" type="text" name="meta_box_news_one_text" value="<?php echo $news_one_text; ?>" />
</td>
</tr>
<tr>
<td>خبر دوم</td>
<td>
<select name="news_two" id="news_two" style="width: 250px;">
<option value="<?php echo $news_two_text; ?>" selected><?php echo $news_two_text; ?></option>
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php the_title(); ?>"><?php the_title(); ?></option>
<?php endwhile; ?>
</td>
<td>
<input size="65" type="text" name="meta_box_news_two_text" value="<?php echo $news_two_text; ?>" />
</td>
</tr>
<tr>
<td>خبر سوم</td>
<td>
<select name="news_three" id="news_three" style="width: 250px;">
<option value="<?php echo $news_three_text; ?>" selected><?php echo $news_three_text; ?></option>
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php the_title(); ?>"><?php the_title(); ?></option>
<?php endwhile; ?>
</td>
<td>
<input size="65" type="text" name="meta_box_news_three_text" value="<?php echo $news_three_text; ?>" />
</td>
</tr>
<tr>
<td>خبر چهارم</td>
<td>
<select name="news_four" id="news_four" style="width: 250px;">
<option value="<?php echo $news_four_text; ?>" selected><?php echo $news_four_text; ?></option>
<?php while($my_custom_query->have_posts()) : $my_custom_query->the_post();?>
<option value="<?php the_title(); ?>"><?php the_title(); ?></option>
<?php endwhile; ?>
</td>
<td>
<input size="65" type="text" name="meta_box_news_four_text" value="<?php echo $news_four_text; ?>" />
</td>
</tr>
</table>
<?php endif; ?>
<?php wp_reset_query(); ?>
</select>
<?php }
add_action( 'save_post', 'saving_meta_box' );
function saving_meta_box( $post_id )
{
if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
if( !isset( $_POST['meta_box_nonce'] ) || !wp_verify_nonce( $_POST['meta_box_nonce'], 'my_meta_box_nonce' ) ) return;
if( !current_user_can( 'edit_post' ) ) return;
$accepted_field = array(
'a' => array('href' => array() )
);
if( isset( $_POST['news_one'] ) )
update_post_meta( $post_id, 'news_one', wp_kses( $_POST['news_one'], $accepted_field ) );
if( isset( $_POST['news_two'] ) )
update_post_meta( $post_id, 'news_two', wp_kses( $_POST['news_two'], $accepted_field ) );
if( isset( $_POST['news_three'] ) )
update_post_meta( $post_id, 'news_three', wp_kses( $_POST['news_three'], $accepted_field ) );
if( isset( $_POST['news_four'] ) )
update_post_meta( $post_id, 'news_four', wp_kses( $_POST['news_four'], $accepted_field ) );
}

ویرایش شده توسط احسان
لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...