Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

What I want to do is to create a simple front-end post submit form, for every different type of post I will include in my Wordpress app. For example there will be articles, events, quick messages and those types will have a different design/structure for a user to see. Author will use those forms to post their content.

As far as I know, I can have a different template for those types with the if in category function but I am interested in alternative solutions (maybe better). I know that there is page_template to add in the array http://wpengineer.com/1229/puplishing-extend-of-wordpress/ but is there anything else?

Also I am having some difficulties to redirect or even echo the posted link (as below). For your concern, I can not echo the $link .

Thank you for your help.

if(isset($_POST['submit'])){

    global $user_ID;

    $new_post = array(
        'post_title' => $_POST['post_title'],
        'post_content' => $_POST['post'],
        'post_status' => 'publish',
        'post_date' => date('Y-m-d H:i:s'),
        'post_author' => $user_ID,
        'post_type' => 'post',
        'post_category' => array(0)
    );

    wp_insert_post($new_post);
}

I tried this for redirect without luck

$pid = wp_insert_post($new_post);
$link = get_permalink( $pid );
echo $link;
wp_redirect( $link );
share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

you need to get the ID from wp_insert_post and make sure you exit or die so:

$pid = wp_insert_post($new_post);
wp_redirect( get_permalink( $pid );
die();

As for the second part you can use the WordPress Template Hierarchy and simply name each one of your custom post type designs as single-{post_type}.php for example if your post type is named event then name that file single-event.php and WordPress will know to use that file for displaying all posts of event type.

share|improve this answer
    
I tried it but I can not redirect the submission form page to the post even though I echoed correctly the link (please se my update). My form is into a php file in themes/twentyeleven and at the top of it I have <?php include("../../../wp-load.php"); ?> I posted this because there may be something wrong with it... –  Punkis Aug 9 '11 at 20:35
    
create a pastebin of your php file. –  Bainternet Aug 9 '11 at 20:41
    
Here it is codepad.org/VcxN7KnN –  Punkis Aug 9 '11 at 20:47
    
the code is a mess, you cant redirect after you echo something and you can't do anything else after you redirect so try this codepad.org/lICoWvpl –  Bainternet Aug 9 '11 at 20:57
    
Thank you very much for this. –  Punkis Aug 9 '11 at 21:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.