Domanda

Sto cercando di aggiungere un modulo in cui gli utenti possono inviare post dal front-end.

Sto seguendo questo tutorial: http: // wpshout.com/wordpress-submit-posts-from-frontend /

Quello che sto facendo è l'aggiunta di questo codice per uno dei miei PAGE- modello. La forma si presenta bene, ma quando clicco sul pulsante di invio che mi dà " Pagina non trovata errore "

Molti dei commentatore dicendo che non sta funzionando. Qualcuno mi può punto nella giusta direzione? Il codice incompleto? Ha difetti? Sto facendo qualcosa di sbagliato?

Grazie

I Towfiq.

È stato utile?

Soluzione

<?php $postTitle = $_POST['post_title'];
$post = $_POST['post'];
$submit = $_POST['submit'];

if(isset($submit)){

    global $user_ID;

    $new_post = array(
        'post_title' => $postTitle,
        'post_content' => $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);

}

?>
<!DOCTYPE HTML SYSTEM>
<html>
<head>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<title>Untitled Document</title>
</head>

<body>
<div id="wrap">
<form action="" method="post">
<table border="1" width="200">
  <tr>
    <td><label for="post_title">Post Title</label></td>
    <td><input name="post_title" type="text" /></td>
  </tr>
  <tr>
    <td><label for="post">Post</label></td>
    <td><input name="post" type="text" /></td>
  </tr>
</table>

<input name="submit" type="submit" value="submit" />
</form>
</div>

</body>
</html>

I found this at Themeforest it's working fine,
you can do a lot of things with this, you have to add some extra code to check if a user is logged in or whatever you want to do,

In the other hand you have to search in the WordPress plugins repo to find out some great plugins,
Search for "frontend"

hope it helps

Altri suggerimenti

Haha, that's my tutorial that failed badly. Sorry bout that, it was something I wrote because I never had the 404 issue everyone else had with it.

The frontend post forms I use most times open up in a modal window, for example, the post forms I made for http://wphonors.com are loaded in the thickbox popup thing, which I believe is why I never had an issue with this. I was able to do anything I wanted with my forms, ajax submit, on submit redirect to submitted posts, or just show a message and go to a random page.

My bad on failing with that tutorial, I had good intentions :)

Maybe try loading them using thickbox, it's really very simple to do. I'm still working on a follow up tutorial to redeem that failed on, but it's been hard to make it work the way most people would be likely to implement it in their sites.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a wordpress.stackexchange
scroll top