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;
    }
}
  • what do you mean by offline user? – Gopal S Rathore Sep 4 '15 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 ?? – Hafiz Usman aftab Sep 4 '15 at 6:34
  • i want insert my post using shortcode i dont used any other person plugin i make my own plugin – Hafiz Usman aftab Sep 4 '15 at 6:37
  • so its the simple process, what you have tried so far and having difficulty? – Gopal S Rathore Sep 4 '15 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; } } – Hafiz Usman aftab Sep 4 '15 at 6:47
5

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.

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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