I’ve been working with the Soundcloud API and have set up their record button to work on my site. The code spits out the new URL of the freshly created soundcloud file once the upload is done.
What I need is to send that URL through some PHP code which allows me to post a new WordPress post automatically.
The piece of javascript code comes from this soundcloud example (more code at the link): http://connect.soundcloud.com/examples/recording.html
<script type="text/javascript">
$("#upload").live("click", function(e){
setRecorderUIState("uploading");
SC.connect({
connected: function(){
$("#uploadStatus").html("Uploading...");
SC.recordUpload({
track: {
title: "Untitled Recording",
sharing: "private"
}
}, function(track){
$("#uploadStatus").html("<a href='" + track.permalink_url + "' class='sclink'>" + track.permalink_url + "</a>");
});
}
});
e.preventDefault();
});
</script>
The #uploadStatus area is what spits out the track.permalink_url … and it works like this. What I need though is to send the URL of the track to a php file which will auto-create a new WordPress post, like below:
<?php
// Create post object
$my_post = array(
'post_title' => 'My Title',
'post_content' => 'TRACKURLSHOULDSHOWUPHERE',
'post_status' => 'publish'
);
// Insert the post into the database
wp_insert_post( $my_post );
?>
I know I need to utilize ajax but for the life of me I cannot figure out how to pull it properly.
Any help would be greatly appreciated.
http://api.jquery.com/jQuery.ajax/#sending-data-to-server
With the jQuery AJAX function, you could do this:
On the PHP end, you can retrieve these variables from the url (they are passed as GET by default, but you can change to POST if you like).