我有下面的表格来更新自定义帖子类型中的帖子。在我的自定义帖子类型中,我有一些ACF字段,我还需要能够更新,但不确定如何更新。我可以更新我的默认WordPress字段,并可以将ACF字段数据调用到我要编辑的字段中,但在提交后不会更新。
下面的自定义ACF字段称为“developer”,如您所见。。
$developer = get_field(\'developer\');
我可以调用字段并将数据输出到。。。
<fieldset>
<label for="postDeveloper"><?php _e(\'Post\\\'s Developer:\', \'framework\') ?></label>
<input type="text" name="postDeveloper" id="postDeveloper" value="<?php echo $developer; ?>" class="required" />
</fieldset>
但当我将该数据传递到(ACF字段名为“developer”,如下所示)。。。
\'developer\' => esc_attr(strip_tags($_POST[\'postDeveloper\'])),
它不会保存编辑和更新帖子。。。我想有些事情我做得不对,因为我这样做是为了更新默认的WordPress字段,所以我想知道是否有人知道如何做?
我所有的代码都在下面。。。
<?php get_header(\'paw-regular\'); ?>
<?php $query = new WP_Query(array(\'post_type\' => \'propertyawardwinners\', \'posts_per_page\' =>\'-1\', \'post_status\' => \'any\' ) ); ?>
<?php if ( $query->have_posts() ) : while ( $query->have_posts() ) : $query->the_post(); ?>
<?php
if ( isset( $_GET[\'post\'] ) ) {
if ( $_GET[\'post\'] == $post->ID )
{
$current_post = $post->ID;
$title = get_the_title();
$content = get_the_content();
$developer = get_field(\'developer\');
}
}
?>
<?php endwhile; endif; ?>
<?php wp_reset_query(); ?>
<?php global $current_post;
$post_information = array(
\'ID\' => $current_post,
\'post_title\' => esc_attr(strip_tags($_POST[\'postTitle\'])),
\'post_content\' => esc_attr(strip_tags($_POST[\'postContent\'])),
\'developer\' => esc_attr(strip_tags($_POST[\'postDeveloper\'])),
\'post_type\' => \'propertyawardwinners\',
\'post_status\' => \'pending\',
);
$post_id = wp_update_post($post_information);
?>
<div class="main wrap">
<div class="ts-row cf">
<div class="col-8 main-content cf">
<form action="" id="primaryPostForm" method="POST">
<fieldset>
<label for="postTitle"><?php _e(\'Post\\\'s Title:\', \'framework\') ?></label>
<input type="text" name="postTitle" id="postTitle" value="<?php echo $title; ?>" class="required" />
</fieldset>
<fieldset>
<label for="postDeveloper"><?php _e(\'Post\\\'s Developer:\', \'framework\') ?></label>
<input type="text" name="postDeveloper" id="postDeveloper" value="<?php echo $developer; ?>" class="required" />
</fieldset>
<fieldset>
<label for="postContent"><?php _e(\'Post\\\'s Content:\', \'framework\') ?></label>
<textarea name="postContent" id="postContent" rows="8" cols="30"><?php echo $content; ?></textarea>
</fieldset>
<fieldset>
<?php wp_nonce_field(\'post_nonce\', \'post_nonce_field\'); ?>
<input type="hidden" name="submitted" id="submitted" value="true" />
<button type="submit" onclick="return redirect()"><?php _e(\'Update Post\', \'framework\') ?></button>
</fieldset>
</form>
</div>