Come aggiungere e inviare campi di input usando uno shortcode?

4 set 2015, 09:26:19
Visualizzazioni: 19.6K
Voti: 1

Come posso aggiungere e inviare un post senza che l'utente effettui il login? Intendo dire che un utente non registrato può aggiungere del contenuto in WordPress e inviarlo, come semplici form in PHP.

Ho provato questo codice:

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
Commenti

Cosa intendi con utente offline?

Gopal S Rathore Gopal S Rathore
4 set 2015 09:31:20

sì, intendo che con il plugin https://plugin-planet.com/usp-pro/ per l'invio di post da parte degli utenti, non voglio dare all'utente l'accesso per effettuare il login su WordPress e aggiungere il suo post. Voglio che possa aggiungere il post direttamente dal front-end gestendo questo codice tramite shortcode, hai qualche idea??

Hafiz Usman aftab Hafiz Usman aftab
4 set 2015 09:34:25

voglio inserire il mio post usando uno shortcode, non voglio usare il plugin di altre persone, voglio creare il mio plugin

Hafiz Usman aftab Hafiz Usman aftab
4 set 2015 09:37:02

quindi è un processo semplice, cosa hai provato finora e dove hai difficoltà?

Gopal S Rathore Gopal S Rathore
4 set 2015 09:42:40

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 Hafiz Usman aftab
4 set 2015 09:47:55

ho aggiunto il codice sia nel post che nel commento

Hafiz Usman aftab Hafiz Usman aftab
4 set 2015 09:48:45
Mostra i restanti 1 commenti
Tutte le risposte alla domanda 1
2

Puoi creare lo shortcode in questo modo:

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
}

Questo è solo un esempio di utilizzo, puoi verificare nel dettaglio qui.

4 set 2015 10:34:06
Commenti

scusa ancora una cosa, come posso aggiungere questo post al mio custom post type :)

Hafiz Usman aftab Hafiz Usman aftab
4 set 2015 10:53:08

Sì, puoi aggiungere post_category nell'array della query :)

dev dev
4 set 2015 11:00:02