 Welcome back to the channel. Today we are going to attempt to do something crazy. First of all, I'm going to create a custom post type here. That's going to collect information. I'm going to use that information and send it to this JSON API. Essentially, it will not be like the server says here, the resource will not be created, but it will be faked. The information it shall be sending shall have to be in a JSON format of sort. And it will have a title, it will have a body, it will have an ID. And of course it will have headers here. So what I'm going to do is I can actually just even use the posts here. So what I'm going to do is just create a bunch of new posts in here. So I'll just run through. Now we are ready. What we're going to do is that we're going to query our posts that we do have here. We'll get the information that we need, which is the title, the body and the ID. And then what I'm going to do is just pass that on. And then eventually we'll see what we get here from our JSON API and see what it returns. All right. The first thing that we're going to do is make a query of sort over on to get all our post data. And so I'll just comment this quickly. So make query of our posts. And we're going to just use a WP query function in Wordpress. So first thing it requires is that it requires some arguments in it. And we're going to set this as a variable. So we're going to call this $query. And we'll get the WP query of that. And we're going to add in our arguments that we should be... We are basically limiting our query so that we don't overburden our database. So the first thing about the arguments is that we're going to have... They're going to be in an array form of sort. So in here we're going to look for the post type of post. And then the next thing that we're going to do is we're going to try to limit it so that we don't have too much data going out. So we'll have posts per page. Explore posts per page. And we shall just have 10 of those. So we'll just do that. That would be a good enough query that we're going to get. After getting our post query, we're going to look for any posts that are in there. So if we say if the query that we've made actually has posts. So have posts. Then we're going to do something about it. So while we have those posts... While we have the posts, we're going to just look through each one of those posts. We're going to say query is actually the post. In here, while we have that post, we're going to look through and add data to our array. So the first thing we're going to do here is we're going to create a new array and we're going to call it data send. And it shall be equal to an array that is empty. So while that is done, we're going to get an array of data which will equal to an array of data. In that, we're going to get our array in here and then we're going to add it to our data send. We shall append to it the array of data. So what here we'll get, we shall just require, we need to get the title. So we have a title. We're basing the information that we need of this particular api. So we'll get the title and that is simply by getting a post. Dash title. Oh, we can just say it's actually equal to get the title. So then we'll duplicate this. This should be a coma because we're working with an array. So we'll get the body. And this one will just equal to get the content and then our user ID for now, we shall just leave it as a static. But ideally we would have gotten the author ID. So user ID, we shall leave it as one and wrap this around in brackets. We're just going to add our data send to see what we are having inside there. Let's just wrap this into its own function. So we'll just call this function getSendData. So call it, we'll give it a function of its own call getSendData and we shall just move everything up. Then we'll then get this function and then instead of this, we shall have that in there and save this. So when we come back here, let's reload this and we see that we get an undefined function wpQuery in our queries API. We'll undo this because it's not affecting in any way. Oh, it should be a new because we're initiating this class. This is a class so we need to add new to it. So when I reload, say that we get back an object of data here what I'm going to do is I'm going to use a JSON encode which is a function of a PHP that allows us to encode any kind of data that we have in two JSON format. So when I reload this, you'll see that we actually have a string. It's actually just a string of data that we do have. So that's what we're going to send to our fake API. So let's try to see how many posters we have here. We have all these posts but we are getting back one. So the reason we're getting one post here is that we are not merging actually these are two arrays. So what I'm going to do is use another PHP method. So we'll use array push which is a default method of PHP and then I will just try to echo what's out here. And you'll see that we now have our full string with more than two, three, four posts. So we have three posts and that's what we actually want. So what I'm going to do is actually I'm going to save this call it data push to API just to be more descriptive. And then now we're going to start working on basically just pushing our information to our URL. So what we're going to do is I'll just copy this and bring it here and I'm going to drop this information here. So we're going to be looking for this particular API where we're going to be posting and we're going to just add it here. And the method that we're going to be using is that we're going to be posting and then when we reach here we're going to use post. That's going to allow us to post information to that URL. So let's quickly look this up and see what we actually need. So if we go to the codex you will see that we have what is here it's explained it retrieves a URL using the htp post method. It needs two arguments the URL and the ads. So in the post an example will have a remote post. Yes we'll put in the URL we'll add the post method which is this another time out and our body is going to actually equal to this data that we are sending here. So what I'm going to do is send this out and then I'm going to check if we get an error from our response we should be able to just throw it off or we should be able to get our response. So if there is an error we shall pass in the response and get the error and else if that passes to be true then we're going to equal out our response. So let's go back to our plugin and reload this. So we get back a response like this because it wasn't an error but because we actually had something that worked out well and the message says it was a 201 and this information was created. Congratulations this is how you send data to any kind of server that is external from WordPress using your own information. So if we made a custom post type it would work out if we just use the ordinary post type that we do have we still get a positive response from the information that we have actually got back. Thank you for watching. If you enjoyed this video please give it a thumbs up and subscribe to make sure that you don't miss out on anything that comes up.