Current status: Solved. . Done
acf_form outside loop
  • I want to use the acf_form on a "Edit your post" page. So there is one page wehe you can edit al the posts. But when i use the acf_form like this, i always only get the update button. No form is shown.


    $options = array(
    'post_id' => '214', // post id to get field groups from and save data to
    );

    acf_form($options )


    I am sure that there is a post with an ID of 214 and it had at least 5 ACF fields inside it. But i keep getting only the upload button.
  • Hi kjappert,

    Does it help if the post_id is an int, not a string?
  • No i tried that! Same result...
  • Interesting...

    I'll do some testing on my end and get back to you.

    Cheers
  • I think I'm having similar problems - I have a custom post type which I'd like to update via a front end form. I've edited the post_id in the ACF front end form function but it doesn't seem to make any difference for where ACF gets the data from or posts it to...
  • Hi @dmje

    The acf_form function is very simple.
    Any chance you can debug it by going through and echoing out the $post_id parameter?

  • Hey guys!

    Great news, I've solved the problem. It is a bug in the acf.php file on line 982 (this may be slightly different between versions)

    the line is:
    $post = isset($overrides['post_id']) ? get_post($_POST['post_id']) : false;


    but needs to be changed to
    $post = isset($overrides['post_id']) ? get_post($overrides['post_id']) : false;


    Thanks for the bug report. This will be fixed in the next version
  • Hey guys, I'm trying to get around this myself. @Elliot- I noticed the above referenced change in the acf.php code. What I'm trying to do is this: use the FE acf_form() to not only edit, but also post new content from the FE. I'm testing using a simple MySQL query in the code with a +1 on there for any new content (will make this less ghetto once I can get something rolling). If I do that and I pull in the current post_id from the DB, I'm immediately hit with a missing form (the +1 yields the same result). I'm wondering if you have a work-around for this or if there is a suggestion for creating new content in the frontend using ACF. I started using Post From Site plugin and combining here, but we're using the repeater field and need that functionality. Thanks!
  • Hi @tbarnes

    There is a discussion in this forum with code examples for using teh FE form to hook in and add a new post!

    I'm not sure on the exact link but I suggest that you search the forum / google for it!

    Cheers
    Elliot