WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] wp_insert_post fron a page (3 posts)

  1. Steffen Jørgensen
    Member
    Posted 3 years ago #

    I'm trying to write a form for visitors to submit content (posts) directly from a page I have created.

    I'm using the "wp_insert_post" function, and found this tutorial:
    http://wpshout.com/wordpress-submit-posts-from-frontend/

    However, I can't make it post to the database — it just returns a "page not found" when submitted.

    Any pointers or tips?

    Thanks in advance.

  2. ojobson
    Member
    Posted 3 years ago #

    At the top of the form, action is left blank:
    action=""

    Action specifies where the form should send the data. The php, which handles the data from the form must be saved to a file on your web server, at the root of the wp installation. If you were to name this 'frontpost.php', you would amend action as follows:

    action="/frontpost.php"

    That way the form sends the data to the php file, which then processes it.

    Hope that helps - I'm trying to use this too, but i'm getting the following error:

    Fatal error: Call to undefined function wp_insert_post() in /homepages/25/d288611421/htdocs/intranet/front-post.php on line 26

    Something in the php doesn't seem to be working.

  3. John
    Member
    Posted 3 years ago #

    If action is left blank and you only have _POST info for the title and content then it works, but if you have any fields that are meant to add meta data, then the php breaks and returns a 404 error.

Topic Closed

This topic has been closed to new replies.

About this Topic