从前端向ACF表单添加标题

时间:2014-12-28 作者:Rizzo

我正在使用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?

1 个回复
SO网友:dadmor

如果要添加包含内容的ACF表单,请单击“签出”this plugin

结束

相关推荐

Front-End Post Submission

我正在尝试添加一个表单,用户可以从前端提交帖子。我正在学习本教程:http://wpshout。com/wordpress从前端提交帖子/我正在做的是添加this code 到我的一个页面模板。表单显示正常,但当我单击“提交”按钮时,它会显示“Page not found error“”许多评论者说这不起作用。谁能给我指出正确的方向吗?代码是否不完整?有缺陷吗?我做错什么了吗?谢谢Towfiq I。

从前端向ACF表单添加标题 - 小码农CODE - 行之有效找到问题解决它

从前端向ACF表单添加标题

时间:2014-12-28 作者:Rizzo

我正在使用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?

1 个回复
SO网友:dadmor

如果要添加包含内容的ACF表单,请单击“签出”this plugin

相关推荐

Front-End Post Submission

我正在尝试添加一个表单,用户可以从前端提交帖子。我正在学习本教程:http://wpshout。com/wordpress从前端提交帖子/我正在做的是添加this code 到我的一个页面模板。表单显示正常,但当我单击“提交”按钮时,它会显示“Page not found error“”许多评论者说这不起作用。谁能给我指出正确的方向吗?代码是否不完整?有缺陷吗?我做错什么了吗?谢谢Towfiq I。