1

How can I add and submit the post without user login? By that I mean an offline user can add some content on WordPress and submit it, like simple forms in PHP.

I tried this code:

public function add_shortcode_fileds() {
    add_shortcode( 'add_fields', 'input_fields' );
    function input_fields( $atts ) {
        $atts='<form method="post" action="">';
        $atts.='<input type="text">';
        $atts.='<input type="submit">';
        $atts.='</form';
        return $atts;
    }
}
6
  • what do you mean by offline user? Sep 4, 2015 at 6:31
  • yes my mean is that plugin-planet.com/usp-pro user submitted post plugin i don't want to give access to user to login on WordPress and add his post i want he add his post from front end i handle this code using short code do you have any idea ?? Sep 4, 2015 at 6:34
  • i want insert my post using shortcode i dont used any other person plugin i make my own plugin Sep 4, 2015 at 6:37
  • so its the simple process, what you have tried so far and having difficulty? Sep 4, 2015 at 6:42
  • public function add_shortcode_fileds(){ add_shortcode('add_fields','input_fields'); function input_fields($atts){ $atts='<form method="post" action="">'; $atts.='<input type="text">'; $atts.='<input type="submit">'; $atts.='</form'; return $atts; } } Sep 4, 2015 at 6:47

1 Answer 1

7

You can create the shortcode like this:

add_shortcode( 'add_fields', 'input_fields' ); 
function input_fields( $atts ) {
    if ( isset( $_POST['gg'] ) ) {
        $post = array(
            'post_content' => $_POST['content'], 
            'post_title'   => $_POST['title']
        );
        $id = wp_insert_post( $post, $wp_error );
    }
    ?> 
    <form method = "post">
        <input type="text" name="title">
        <input type="text" name="content">
        <input type="submit" name="gg">
    </form>
    <?php
}

It's just a sample usage, you can check in detail here.

2
  • sorry one more thing how i add this post in my custom post type :) Sep 4, 2015 at 7:53
  • Yes, you can add post_category in query array :)
    – dev
    Sep 4, 2015 at 8:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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