Post form as custom post
I'm new to WordPress and need to create a website including a special form, with which I can upload photos, set my position on an OpenStreetMap and choose from several dropdown menus.
Here you can find an example of how it should look like:
I already did this:
Created a page template with the form
form id="new_post" name="new_post" method="post" action="" enctype="multipart/form-data"
Made the form submitable for users who are logged in (is this a secure solution?)
?php if ( 0 == $current_user-ID ) { wp_loginout(); echo " to submit a post"; } else { echo 'fieldset class="submit" input type="submit" value="Los" tabindex="40" id="submit" name="submit" / /fieldset input type="hidden" name="action" value="new_post" /'; wp_nonce_field( "new-post" ); } ?
When the form is submitted this php code is executed:
if( 'POST' == $_SERVER['REQUEST_METHOD'] !empty( $_POST['action'] ) $_POST['action'] == "new_post") { $new_post = array( 'post_title' = "roadkill entry", 'post_content' = "testcontent", 'post_category' = array(0), 'post_status' = 'publish', 'post_type' = 'roadkills' // this is my custom post ); $pid = wp_insert_post($new_post); $link = get_permalink( $pid ); wp_redirect( $link ); }
But I will end in an page not found. http://www.citizen-science.at/wordpress/roadkill/eintrag-hinzufugen/
When I create an entry via the admin GUI I am able to view the single post, but not the archive http://www.citizen-science.at/wordpress/roadkills/dafdf/
Oh yeah, here is how I am registering my post type:
?php
add_action( 'init', 'create_post_type' );
function create_post_type() {
register_post_type( 'roadkills',
array(
'labels' = array(
'name' = __( 'Roadkills' ),
'singular_name' = __( 'Roadkill' )
),
'public' = true,
'has_archive' = true,
)
);
}
What did I miss here? (I already got it working yesterday, but somehow it broke)
Topic map forms custom-post-types Wordpress
Category Web