【问题标题】:How do I redirect after submission with acf form?使用acf表单提交后如何重定向?
【发布时间】:2017-04-03 22:51:02
【问题描述】:

如何在使用高级自定义字段表单提交新帖子后重定向用户?

文档说:

<?php                    
  $args = array(
    'post_id' => 'new_1',
    'field_groups' => array( 357 ),
    'submit_value' => 'Submit Story', 
    'return' => '%post_url%'
   );
   acf_form( $args );
?>

但我得到一个空白页。

评论后更新,还是空白页:

acf_form(array(
    'post_id'   => 'new_post',
    'post_title'    => true,
    'post_content'  => true,
    'return' => add_query_arg( 'updated', 'true', get_permalink())
));

在函数中也试过这个钩子,还是空白。

function my_acf_save_post( $post_id ) {
    wp_redirect(get_permalink($post_id)); exit;
}
add_action('acf/save_post', 'my_acf_save_post', 20);

注意

帖子已创建

【问题讨论】:

  • 尝试使用'return' => add_query_arg('updated', 'true', get_permalink()), ?
  • @vel 谢谢,我试过但没有,我得到一个空白页。检查我的问题,因为我已经更新了它
  • 不要在acf/save_post中写exit
  • 应该返回 return $post_id;
  • 什么都没有,再试一次,还是空白:(

标签: wordpress advanced-custom-fields


【解决方案1】:

问题出在缓冲区中

    <?php 
    /* 
    Template Name: Front 
    */ 
    ob_get_clean(); 
    acf_form_head(); 
    get_header(); 
    ?> 
    <div id="content"> 
    <?php 
    acf_form(array( 
    'post_id' => 'new_post', 
    'post_title'    => true, 
    'post_content'  => true, 
    'return' => add_query_arg( 'updated', 'true', home_url() ), 
    )); 
    ?> 
    </div> 
    <?php get_footer(); ?>

【讨论】:

    【解决方案2】:

    遇到同样的问题,%post_url% 现在似乎出现故障,但对vel 建议的回退到主页并不满意。

    我需要在编辑后返回帖子页面并执行以下操作:

    acf_form(array(
        'post_id'   => $_GET['pid'],
        'return' => get_permalink($_GET['pid'])
    ));
    

    希望这会有所帮助! 最好的问候

    【讨论】:

      【解决方案3】:

      在我的例子中,我正在使用Sage 9 构建一个站点,并且我必须将 acf_form_head() 放在我的 base.php 中的 &lt;!doctype html&gt; 之前。 @Foxaii proposed this solutionRoots 论坛上。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-06
        • 1970-01-01
        • 2013-04-13
        • 1970-01-01
        相关资源
        最近更新 更多