开发者

How can I correctly redirect user to the submitted post and define a template for each new post in Wordpress?

开发者 https://www.devze.com 2023-03-27 00:48 出处:网络
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

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 even I echo the link

$pid = wp_insert_post($new_post);
$link = get_permalink( $pid );
echo $link;
wp_redirect( $link );


you don't save the returned p(age_)id from the wp_insert_post(). just use:

$pid = wp_insert_post($new_post);

and the rest of the code should work fine

0

精彩评论

暂无评论...
验证码 换一张
取 消