I’m following this tutorial: https://www.advancedcustomfields.com/resources/using-acf_form-to-create-a-new-post/
to create new post.
this is my code:
`<?php $my_fields = array(
<h1><?php the_title(); ?></h1>
<?php the_content(); ?>
<!–<p>My custom field: <?php //the_field($provider_name); ?></p>–>
<?php $new_provider = array (
‘post_id’ => ‘new_post’,
‘new_post’ => array(
‘post_type’ => ‘provider’,
‘post-status’ => ‘draft’
‘field_gruops’ => $my_fields,
‘form’ => true,
‘return’ => ‘/’,
‘html_before_fields’ => ”,
‘html_after_fields’ => ”,
‘submit_value’ => __(‘Create a new provider’),
‘updated_message’ => __(“The provider has been saved”, ‘acf’)
– acf_form_head(); is in the header
– post type is custom
I can see the post but getting this error:
Warning: array_merge(): Argument #1 is not an array in C:\xampp\htdocs\ddo_wp\wp-content\plugins\advanced-custom-fields\core\api.php on line 1185
There are a few things that are going on in the code above, which may be the way you’ve copy/pasted it, but are worth noting.
Firstly – some programs style apostrophes as a slightly different type of character that looks a lot like an apostrophe but is more akin to a grave, or an acute accent. MS Word is killer for this, but a lot of other programs do it too and it looks like something similar is happening in your code.
– If we fix this, we can then see a couple of other issues – on line 6, you don’t close your php tag before the <h1>.
– Your HTML comment is also missing a hyphen, as comments should be <!– –>, however this won’t cause anything other than styling issues for you.
– The parameter “field_groups” has been misspelled as “field_gruops” which may be the underlying cause of your error.
– The updated message has some curly quotes in it as well.
Fixing all of the above gives you some code that looks more like the following:
<?php $my_fields = array( 'field_57065cfb19c17', 'field_57065dc319c18', 'field_57065e1a19c19', 'field_57065ea919c1a' ); ?> <h1><?php the_title(); ?></h1> <?php the_content(); ?> <!-- <p>My custom field: <?php //the_field($provider_name); ?></p> --> <?php $new_provider = array ( 'post_id' => 'new_post', 'new_post' => array( 'post_type' => 'provider', 'post-status' => 'draft' ), 'field_groups' => $my_fields, 'form' => true, 'return' => '/', 'html_before_fields' => ”, 'html_after_fields' => ”, 'submit_value' => __('Create a new provider'), 'updated_message' => __("The provider has been saved", 'acf') ); acf_form($new_provider); ?>
If you run that through, it may work a little better?
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
© 2023 Advanced Custom Fields.