我正在使用ACF从前端制作自定义帖子。我在我的主题中创建了一个页面,代码如下:
// generate post title on submit
function auto_title_insert( $value ) {
$value = $_POST["fields"][\'field_5481df76aed49\'].\'-\'.$_POST["fields"][\'field_5481df80aed4a\'].\'-\'.$_POST["fields"][\'field_5481df86aed4b\'].\'-\'.$_POST["fields"][\'field_5481e101af995\'];
return $value;
}
add_filter( \'title_save_pre\', \'auto_title_insert\' );
// update post title on update
function my_acf_update_value( $value, $post_id, $field ) {
global $_POST;
$new_title = $value;
$new_slug = sanitize_title( $new_title );
$my_post = array(
\'ID\' => $post_id,
\'post_title\' => $new_title,
\'post_name\' => $new_slug,
\'post_type\' => \'mycpt\',
);
wp_update_post( $my_post );
}
add_filter(\'acf/update_value\', \'my_acf_update_value\', 10, 3);
// other
add_action( \'wp_print_styles\', \'custom_acf_deregister_styles\', 100 );
function custom_acf_deregister_styles()
{
if (! is_admin() )
{
wp_deregister_style( \'wp-admin\' );
}
}
acf_form_head();
get_header();
?>
<div id="sidebar_layout" class="clearfix">
<div class="sidebar_layout-inner">
<div class="row grid-protection">
<?php get_sidebar( \'left\' ); ?>
<!-- CONTENT (start) -->
<div id="content" class="<?php echo themeblvd_get_column_class(\'content\'); ?> clearfix" role="main">
<div class="inner">
<?php themeblvd_content_top(); ?>
<?php while ( have_posts() ) : the_post(); ?>
<?php get_template_part( \'content\', themeblvd_get_part( \'page\' ) ); ?>
<?php
$args = array(
\'post_id\' => \'new\',
\'field_groups\' => array( \'acf_timesheet\' ),
\'post_type\' => \'tspg_timesheet\',
\'post_title\' => $_POST["fields"][\'field_5481df76aed49\'].\'-\'.$_POST["fields"][\'field_5481df80aed4a\'].\'-\'.$_POST["fields"][\'field_5481df86aed4b\'].\'-\'.$_POST["fields"][\'field_5481e101af995\'],
);
acf_form( $args );
?>
<?php themeblvd_page_footer(); ?>
<?php if ( themeblvd_supports( \'comments\', \'pages\' ) ) : ?>
<?php comments_template( \'\', true ); ?>
<?php endif; ?>
<?php endwhile; ?>
<?php themeblvd_content_bottom(); ?>
</div><!-- .inner (end) -->
</div><!-- #content (end) -->
<!-- CONTENT (end) -->
<?php get_sidebar( \'right\' ); ?>
</div><!-- .grid-protection (end) -->
</div><!-- .sidebar_layout-inner (end) -->
</div><!-- .#sidebar_layout (end) -->
<?php get_footer(); ?>
由于某些原因,帖子标题没有生成,帖子也没有创建。我做错了什么?
我使用了这篇帖子的建议:How to update a custom post title from a front-end form using ACF fields?