Support

Account

Home Forums Backend Issues (wp-admin) wp_update_post problems

Solving

wp_update_post problems

  • I let users post. when they post i get a mail with a link that publish there post with a wp_update_post function.

    The problem is with one of the post fields which is a date picker field. for some reason if i use that publish link (with the wp_update_post function) the date returns in that format: 1-10-2010 (instead of 1/10/2010).

    *that is critical for me because i use that field to calculate age with php.

    Now if i click “update” on the post edit screen it fixes the issue. also if i publish the post through the regular “publish” button on the post edit screen it works fine. the problem occurs only when using the wp_update_post function to publish the post.

    This is my publish code:

    <?php $thispropostid = $_GET[‘thispropostid’]; $postData = [ ‘ID’ => $thispropostid, ‘post_status’ => ‘publish’ ]; wp_update_post( $postData );?>

    Any Ideas?

    Thanks.

  • Hi @bentalgad ,

    Thanks a lot for reaching out.

    You may consider adding the date in the correct format to the wp_update_post.

    This will ensure that only the specified format is saved.

    https://codex.wordpress.org/Function_Reference/wp_update_post

    Hope this helps.

  • Thanks, but actually now i see my problem is more serious, until i don’t manually press “publish” / “update” on the post edit page the ACF fields don’t return anything…

  • Hi @bentalgad ,

    Which filter are you hooking into?

    Kindly share with us a more comprehensive code sample on how you are updating the field so that we may be able to help.

    Hope to hear from you soon.

  • The post is created by a user using formidable pro form which his fields are connected to the ACF fields of the post.

    Once the post is created i get a mail saying there is a new post and i have a link to publish.

    The link is a link to a page which uses is own template php file. in that php file i use that code:
    <?php $thispropostid = $_GET[‘thispropostid’]; $postData = [ ‘ID’ => $thispropostid, ‘post_status’ => ‘publish’ ]; wp_update_post( $postData );?>
    To publish the post.

    Obviously the $_GET['thispropostid']; is getting the post id from the url attribute which holds the post’s id.

    That’s it. that’s the whole story… Nothing more.

  • Hi @bentalgad

    I think the issue is that you only add the custom field values from the Formidable form. ACF saves two entries in the database, the value and the reference. The reference is needed to let ACF know which field you want to update or get the data.

    To fix it, kindly update the custom field value by using the update_field() function. Don’t forget to use the field key instead of field name on that function.

    I hope this makes sense 🙂

  • but how will i get the value of the created post ACF field?

  • Hi @bentalgad

    To get the custom fields value from the form, you need to get in touch with Formidable support instead. If you can get the posted value, then you can update the post’s custom fields value by using the update_field() function.

    Please keep in mind that you need to do it after the post is created. They should have a hook that can be executed at that moment.

    I hope this helps 🙂

Viewing 8 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic.