我已经完成了 foreach 循环以将自定义帖子类型发送到前端。我有一个名为“order_status”的自定义字段。当我在循环中查看我的列表的前端时,我想添加一个按钮来将这个特定的帖子“order_status”更改为不同的值..我的代码..
<? foreach ( $postslist as $post ) :
setup_postdata( $post );
?>
<div class="profile_order_row">
<a href="<?php the_permalink(); ?>"> <?php the_author(); ?> <?php the_title(); ?></a>
<?php
Global $post;
if ( isset( $_POST['submit'] ) )
{
if( ! isset( $post ) ) {
echo 'Post not set';
die();
}
else if( ! isset( $_POST['staatus'] ) && ! empty( $_POST['staatus'] ) ){
echo 'Error';
die();
}
$postid = $_POST['post_id'];
update_post_meta($postid,'order_staatus','1');
}
$staatus = get_post_meta($post->ID, 'order_staatus', true);
echo print_r($staatus);
?>
<form method="post" action="">
<input type="hidden" name="post_id" value="'.$post->ID.'" />
<input type='text' name='staatus' value='<? echo $staatus ?>' />
<input type='submit' value='save' />
</form>
</div>
<?php endforeach; wp_reset_postdata(); ?>