WordPress.org

Ready to get started?Download WordPress

Forums

Custom post type and front page submission. (2 posts)

  1. Mirko G.
    Member
    Posted 1 year ago #

    Hi guys,

    Even if I've been using WordPress since the first release I'm pretty new to both PHP and Worpdress hooks. So I guess I need some advice about how to approach a problem.

    Objective: Create a custom post type with separated taxonomy and mandatory custom fields and allow users to submit from the front-end and review only their own entries.

    I'd like to do it with a plugin so that I can re-use it and, well, make it public.

    On back-end side I don't have many problems. I've been able to create the new post type with its own taxonomy. Still to be fine-tuned but it works.

    I have some problem with the front-end. I'm creating the form to submit the posts but I don't know how to publish it.

    • I started with a shortcode to put in a page, but having a form I'd need to add something in the HEAD (before get_header) for verification and I'm not sure how to do it from a shortcode.
    • I thought about a template to be applied to an empty page but I don't know how to make the template "selectable" by the user in the page editor.
    • Then I'm still trying to figure out how to publish the list of posts. I thought about using the single-<name>.php but I don't know if it's the "cleanest" way.
    • I guess that the mandatory fields can managed within the same form without using any specific WordPress function, isn't it?

    Ok, I'm ready to learn! :-)

    Any advice?

  2. bcworkz
    Member
    Posted 1 year ago #

    1. Can't be done from shortcode. Shortcode is executed when it is encountered in content. By then, the head has been sent and closed, and the body opened. Do what you need in head from your plugin.

    2. See Pages#Creating_Your_Own_Page_Templates. Assuming your frontend editor works the same as the backend.

    3. Makes sense to me to use your theme's methods and templates to display posts. Even if it's not the "cleanest".

    4. You don't have to use WP functions, but they can make things easier. You might consider using javascript or JQuery to check the fields before posting the form, could reduce server requests. You still need to re-verify all posted data at the server since the user may have compromised the client side script.

    An ambitious newbie coding project! Good luck.

    Never forget that any user submitted data can be malicious. Be careful!

Topic Closed

This topic has been closed to new replies.

About this Topic