Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

This question already has an answer here:

I am using Wordpress 3.3.1 and building a small API to be able to send an SMS to insert data.

<?php 
/**
 * Template Name: API: Response
 *
 */

print_r('hello');

?>

The following $_POST variables are being sent from the SMS provider

$_POST['message']
$_POST['from']

When using $_POST['message'], $_GET['message'] or $_REQUEST['message'] Wordpress gives me a 404. Works like a charm when using $_POST['_message'].

Any ideas? Can't find it in the reserved taxanomies.

share|improve this question
    
Try var_dump( $_REQUEST ); instead of print_r('hello');. –  Ralf912 May 7 '13 at 14:13
add comment

marked as duplicate by toscho Jul 6 '13 at 16:53

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1 Answer

To insert a post into the WordPress database, whether you are doing it as a logged in user to the current WordPress installation or over XML-RPC (or any other remote methodology) you need to be using something along the lines of;

  $the_post = array(
     'post_title' => 'Post Title',
     'post_content' => 'My post content',
     'post_status' => 'publish',
     'post_author' => 1,
  );


  wp_insert_post( $the_post );

In the case of using a form or some other programmatic means to insert a post, your code might look like this;

  $the_post = array(
     'post_title' => 'Post Title',
     'post_content' => $_POST['message'],
     'post_status' => 'publish',
     'post_author' => 1,
  );


  wp_insert_post( $the_post );

The bottom line is this, no matter how you decide to insert a post - be it via sending an SMS, using a remote form, smoke signal or the like - your code that handles and processes the data to be inserted must reflect the above examples (in its most simplistic form).

So, what does your code look like that is handling the processing of your incoming SMS message?



References:

wp_insert_post - WordPress Codex

share|improve this answer
    
I have no issues creating the page, but when using $_POST['message'] (or any other than that) I receive a 404 from Wordpress. I've even cleared everything from the template, only using this: <?php /** * Template Name: API: Response * */ print_r('hello'); ?> /api/response/?message=lalalala Gives a 404. /api/response/?_message=laalalal /api/responsie/?Message=lalalal Does not give a 404. –  vlarsson May 29 '12 at 6:50
add comment

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