5

ユーザーが投稿を追加/編集するためのフロントエンド管理者を作成しています。私はすでにポスト追加フォームを作成しましたが、機能しますが、編集フォームは機能しません。

関数.php

function add_new_post( $post_id )
{
    if( $post_id == 'new' ) {
        // Create a new post
        $post = array(
            'post_title' => $_POST["fields"]['field_52c810cb44c7a'],
            'post_category' => array(4),
            'post_status'  => 'draft',
            'post_type'  => 'post'
        );

        // insert the post
        $post_id = wp_insert_post( $post );

        return $post_id;
    }
    else {
        return $post_id;
    }
}add_filter('acf/pre_save_post' , 'add_new_post' );

index.php

<div id="updateform-<?php the_ID(); ?>" class="collapse">
    <?php
    echo get_the_ID();
    $args = array(
        'post_id' => get_the_ID(), // post id to get field groups from and save data to
        'field_groups' => array(31), // this will find the field groups for this post (post ID's of the acf post objects)
        'form' => true, // set this to false to prevent the <form> tag from being created
        'form_attributes' => array( // attributes will be added to the form element
            'id' => 'post',
            'class' => '',
            'action' => get_permalink( get_the_ID() ),
            'method' => 'post',
        ),
        'return' => add_query_arg( 'updated', 'true', get_permalink() ), // return url
        'html_before_fields' => '', // html inside form before fields
        'html_after_fields' => '', // html inside form after fields
        'submit_value' => 'Update', // value for submit field
        'updated_message' => 'Post updated.', // default updated message. Can be false to show no message
    );
    acf_form( $args );
    ?>
</div>
4

3 に答える 3

1

投稿を保存するには、save_postnotを使用する必要がありますpre_save_post。基本的pre_save_postに新しい投稿に使用されます。

これを以下で使用しますadd_filter('save_post' , 'add_new_post');

于 2014-03-14T04:55:53.527 に答える
0

そのためのプラグインを作成しました:

  1. フォーム アクション https://wordpress.org/plugins/forms-actions/

アクションを自分の ACF フォームに追加します。

  1. ACF フロントエンド表示 https://wordpress.org/plugins/acf-frontend-display/

フロントエンドに ACF フォームを表示する

于 2015-03-30T10:49:48.353 に答える