 Alright, welcome back to the channel. Last time we were here, we were able to make an endpoint on the REST API to receive information from a particular callback. While we were not using an active callback, we were using Postman to help us to post data. And in the last time we tried to do that, we actually saw that we got back useful information and were able to cross check our password and make sure that everything is working out well. Now, this check of the password that I made available to you is not the default of how you do it. By default you can use the REST API to check whether the person is allowed to actually post any data. So you can check whether the person has those privilege to do so. But in this particular case, we wanted to be very, very explicit about who are sending the data and whether they were allowed to actually send the data that was coming across. So in this particular exercise that we're doing, I'm going to ask for more data to come from the Postman or our API and then we'll save it into a custom post type. That is the WordPress thing that I'm going to do. Instead of doing anything else, it could trigger so many things but what I'm going to do is just save it in a custom post type to show you that we can actually have that data doing so many other things. So at the bottom here, ideally I would open a new page to make a new page to code our custom post type then import it in our current file but I'll just leave that to run for now. So we're going to have a function and call this setupPostType. Now, of course this is not a very good name because you could have it clashing with so many other WordPress functions. Let me add some space here but I'm going to prefix it with a take a press underscore setupPostType and what we're going to do here is we're going to require that function when we add action and the action that we're going to use is that so use the init hook and then we can call in this particular function. Now the init will allow us to run this function when WordPress has loaded. So we're going to use the registerPostType method of WordPress or a function which is inbuilt and it requires two arguments. In that case it requires the name or the ID of the post type and in this case we're going to call it a PI data and then what we're going to do is we're going to pass in some arguments but I'll leave this as a variable so that we can use it up here. So let's start our variables because this is going to be a huge array of our content so let's save that in here. So we come back to our array and inside here I'm going to add that it should be public because we want to use it in the admin area. Now because we've set it as public WordPress assumes that we also want to use it in a queryable position as true. So that means you being used on the front end if you read the WordPress documentation here you will see that when we set public as true in that main interface things like publicly queryable automatically inherit from the public so making it real so what we're going to do is we're going to publicly queryable and we're going to set it to false. So we'll set that as false because we're not going to use it on the front end. At least for now we shall not be using that if you want to do that you can use it on the front end there's no problem. So the next thing we need most importantly is a label and for our label we shall leave it translatable so we bring in our strings the double underscores and then we shall pass in the M and we shall call it API data and then of course here we add our text domain and that text domain is usually what we have passed in here so I'll just use this for now then we shall need a menu icon and the menu icon we shall get from dash icons so I'm going to say dash icon dash and then let me just open up dash icons real quick so in dash icons we have the dash icons analytics and that's what I'll use let me not look for something else and we'll paste it here and then we shall also choose to say it supports and that's we're going to look for things like the editor the title and so on so this is an array of variables so inside here we shall have a title and then the other thing that I'll do is editor here and that works out well for us so with this we are ready to have our custom post like showing on the front end so let me sorry on the back end in that main area so let me go into my URL right now so if we come to our back end you'll actually see that we have something called API data and if you go in here you can create a new post if you want to and it has a title and an editor now we're going to populate the data that's going to go inside here from our callback that we are getting so let's go back into our code here so just like we received the name and the password here we can receive a title so I'm going to have a new variable called title and it will be coming from the parameters and we're going to be passing a title from our API for example this could be anything but for now I'm choosing to have a title and then outside the title I'm going to have a body of text so I'll change this to body so the way we align this data the way we call it in here is the way it should come from our JSON being posted on postman so once we've set this up I'm going to come to the point where we have reached our server here and so I am going to get the information inside our post type so the first thing that I'll do is I'm going to use a wp insert post which is a function of WordPress and it just inserts data inside the post types that you do have now this insert post type actually requires some arguments so those arguments we shall call them post arguments that's what we'll use right now we are going to set up our post arguments so we'll set up our post arguments right now because this will be an array of data and forget our semicolon and inside here we're going to have a post title because we need to set our title but you can skip it if it's not something you're looking at doing but it's good to identify your title and what we're going to do is we're going to pass in our title that we get from here so we're going to get this and paste it here but what we want to do is we want to make sure we strip all tags so let's say the api by some rare chance passes in some html data and that's not good for our title so we strip all html tags from using the WordPress function of wp strip all tags and that will make sure that our title is actually clean the next thing that we're going to do is we're going to pass in the post content now you might be asking how does he know what to get from here post title post content these are part of the post object so when you go to the WordPress codex you're able to search for things like this if we do the dowp insert post here and search for it on the codex or the code reference we'll see that we have insert or update a post and what happens here is that you have all these parameters assigned for you you have the post title exit the status can have the post type so many other things that you can choose from if you want to make this a child of a particular variant that is also available and then you also have the post content that we were looking for here so we're going to have our post content and what we're going to do is send that up to be the body that we stored inside the variable from here from our parameters now the other thing that we're going to do is set our post status and we shall choose to have it as published so publish will be our default set this in a post type and the post type that we have is what we already named as API data we need to be exact we don't want to send it to the other post or any other post type so we're going to send it to our API data so I'm going to save this so what I'm going to do right now is I'll set a variable and call it a post var I'm going to use this here to add to our message this is successful instead of having data you've reached the server I'm going to set it to something completely different now so if this actually happens if the post var happens then we're going to set a new message we're going to say if if post var is true then we shall have this message showing up so the message will be post has been added post was successful and the other thing that I'm going to do is comment out this API data we don't need to show that whenever we go to our postman so I'll go to postman we have a URL that's correct we have YouTube name we have our password we have our title we have our body and all of this is in JSON so what I'm going to do is now just ping our endpoint and when I do that we get back a message of post was successful so let's go back to our backend and see what happens and nothing shows up so let's see we have an error and if I quickly look you'll see that we saved it in the post type of API underscore data yet what we have here is API data so I'll save this again sorry for the error that happens in coding so I'm going to ping it again successful so I'm going to check for the API data and we see that we have a new post made and when we go to edit it we'll actually see that we have our body in here so Laura Mepsum is not so great at this time so that's wonderful we've made an endpoint where people can just even write articles and post information straight into our website without having to log in here they can do it from there and you could set this up on different places you could set it up on github you could set it up on any place that allows you to do postings and then just create an endpoint of rest on your WordPress website using a simple plugin like this allow for the user to post and then you can move on with life very simple and very quick and effective so thank you for watching this video series if you want to see me do anything more with the post method and post endpoint please let me know in the comments but I hope this gives you a bit of an outlook on how to use webhooks or callbacks to do a number of things so if you enjoyed the video please give it a thumbs up share it with your friends comment and even just consider subscribing for more content thank you for watching and enjoy your day