我很困惑为什么这不起作用。我已经尝试了一些不同的选项,但在线的所有内容对我来说都太过通用了。
我想做的事情非常简单。我是否需要构建表单然后引用数据输入并将表单“保存”到ACF API或者是否为我呈现表单?
<?php
acf_form_head();
function my_pre_save_post( $post_id ) {
// check if this is to be a new post
if( $post_id != 'new' ) return $post_id;
// Create a new post
$post = array(
'post_status' => 'publish' ,
'post_title' => 'title' ,
'post_type' => 'job' ,
'field_groups' => array($_POST["fields"]['field_533f68b959002'], $_POST["fields"]['field_533f68128af07'], $_POST["fields"]['field_533f684f810ab']),
);
$post_id = wp_insert_post( $post );
do_action('acf/save_post', $post_id);
return $post_id;
}
add_filter('acf/pre_save_post' , 'my_pre_save_post' );
get_header();
?>
<div id="primary">
<article class="white_bg">
<h2>Post Job: Futura</h2>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
<?php
$args = array(
'post_id' => 'new',
'post_type' => 'job',
'field_groups' => array($_POST["fields"]['field_533f68b959002'], $_POST["fields"]['field_533f68128af07'], $_POST["fields"]['field_533f684f810ab']),
);
acf_form( $args );
/*
$options = array(
'post_id' => 'new_post',
'new_post' => array(
'post_type' => 'job',
'post_status' => 'publish'
),
'field_groups' => array('field_533f68b959002', 'field_533f68128af07', 'field_533f684f810ab'), // 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' => '',
'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' => 'Post New Job', // value for submit field
'updated_message' => 'Your opening has been posted!', // default updated message. Can be false to show no message
);*/
?>
<?php endwhile; ?>
<?php endif; ?>
</article><!-- #content -->
</div><!-- #primary -->
<?php get_sidebar(); ?>
<?php get_footer(); ?>