Thank you for this. I needed to send the output of a js function I built to an API endpoint for the app developer I am working with. This video was one of the links in the chain that I needed. I appreciate how clearly stated and demonstrated this was.
Thank you for keeping it simple. I need a bit more information for my purpose but now I understand how custom endpoints work. You put me on the right track. Happy New Year!
Thank you man, watched and learnt...neat and clean! I just subscribed, yes, because of your great content, but above all after seeing again the pic at 6:48...actually also because you didn't bore any of us with wasting time in asking us to subscribe, to ring the bell, to comment below, to pet our cat, to clean our room, etc etc... Hvala! (Am i right if I guess that your English is pretty amazingly Serbian?)
Thanks for watching and subscribing man :) I appreciate it. My accent is Croatian, but Serbian and Croatian are very similar languages :) so I understand why you would think that.
Great tutorial man, very useful. It makes the output of the json object so much cleaner. With custom fields, I believe I can use it to create an online task organizer.
hi do you have a video for WP REST API where we can update the data? I dont see any videos regarding to that. all of the youtube videos available are just getting data
I think the lack of those videos have something to do with the authentication. It's pretty tricky to do in WP. But that is a good idea. I will see what I can do. Thanks for the suggestions.
@@WatchandLearnTutorials actually, i'm also not sure about that wp-json. Because most of tutorial use that to call json. But i dont know where to find it. Like where it is come from
@@nurulfarhana2773 You are going to have to be more specific with your questions, I'm not sure what you mean. And also if you are a beginner you probably don't even need this right now, this is used if you want to make your frontend with JavaScript (React, Vue, Next) or maybe provide data for mobile applications.
@@nurulfarhana2773 I think that I know what you mean and I had the same issue. I'm also getting a 404 when I try to access /wp-json/wl/v1/posts. Try: /?rest_route=/wl/v1/posts It worked for me.
I believe that you could make custom endpoints for WooCommerce. However Woo comes with it's own API, so maybe better use that: docs.woocommerce.com/document/woocommerce-rest-api/ and documentation is here: woocommerce.github.io/woocommerce-rest-api-docs/#introduction
Thanks, but how can I get my custom taxonomies, usually recieved them by 'get_field()' method, but in the plugin wl-api it doesn't work. Please, help, if you know.
Isn't get_field() an ACF function? Are you defining your taxonomies with ACF? If not, then this not the function you should be using. Also take a look at these videos: th-cam.com/video/76sJL9fd12Y/w-d-xo.html , th-cam.com/video/5rSfAkLO5eo/w-d-xo.html maybe you get the idea from there. You can use WP_Query to get pretty much anything from WP. I also have a whole series about it, so you can also take a look at that: th-cam.com/play/PLUBR53Dw-Ef8RvXF4iEU6UnhOlrcfIYn6.html
You need to handle pagination yourself, by using something like WP_Query it has pagination built in. You would use that instead of get_posts. I can't explain the entire process in the comment. Maybe I will make a video about it.
You can use developer.wordpress.org/reference/functions/wp_get_theme/ for getting the theme and probably developer.wordpress.org/reference/functions/get_plugins/ for getting the plugins. Never used those two functions but I hope they will work.
@@WatchandLearnTutorials thank you I used WordPress one time only and it was in AWS lightsail VM , I now understand from you we going to install something on our device with folders in real WordPress is am right.
Thank. so i have one problem if i want to display all my content but only four elements i seen but i have more than four element sory for my bad english
And another way too return html by reading the url? May so? : function cathy_plugin_demo_filter_content($content) if (isset($_GET['pups'])) $content = 'huhu';
@@notetomgaming6701 I will make a few videos about this soon. There has been a surge in WP Custom Endpoint questions, so I will expand on it a bit with a few more video examples.
Hi thanks for your video! I'm looking for a way to disable Rest API for a user role called 'external_user'. This user role can see right now alot of posts and pages information with when we put wp-json on the URL (users, pages, posts...) I use actually the plugin DISABLE REST API but it prevent only not logged users to see json informations. i need to do the same thing with external_user role. If it's not possible, can I redirect this user role (and only external_user role) to 404 pages if we try to put an URL with wp-json ? Thanks.
You don't. You handle pagination on the frontend, however, you can needed data to this endpoint if you want, something like number_of_posts, number_of_pages etc. Default routes already send that data in the response header, so maybe custom end points do the same, I'm not sure. Check this video to see what I mean, I create pagination here on frontend with Svelte: th-cam.com/video/eKHoFSVyRV0/w-d-xo.html
You would have to learn some basics of PHP and how WordPress loop works, and also how WordPress custom queries work. I have a playlist for WP custom query so you can check that out: th-cam.com/play/PLUBR53Dw-Ef8RvXF4iEU6UnhOlrcfIYn6.html ... But before that I recommend that you get familiar with the basics of PHP.
Really good video! The speaker sounds like an Easter European selling soviet weapons on the black market “Far be it from me to question your logic, you must have your reason you want this nuclear warhead. Not my business.”
Hey Great Tutorial. Much needed. I have one problem. How can I get the link/url of the current post? I am adding post_link but its not working. I want the permalink of a post or all posts. $data['Link'] = $post[0]->post_link; not working. Please HELP!
@@WatchandLearnTutorials Understandable! Could you recommend a resource or a video for the same, sir? I am literally stuck. Thanks in advance (I have to send audio files to the Media Library & then grab & share there link on my flutter application...)
@@sameermishra3598 I don't know of any such link, sorry. But just keep this in mind, audio file is just a file, so try looking for tutorials about file upload, it doesn't matter if it's an audio, image or text document, the procedure should be the same.
First of all thank you for the video it will help me a lot Im a kind of a newbe with php... is it dificult to get author name? since the default API gives me an ID and my host block the users endpoint for security reasons (and I think it should stay like that)
Maybe you could do it by doing something like: $data[$i]['author'] = get_the_author_meta( 'display_name' , $post->post_author ) Maybe something like that will, work, but I haven't tested it.
@@WatchandLearnTutorials Thank you, I'll try that looking on the documentations. Now I having a problem, in the browser and postman my request works fine, on an axios request from react I receive a CORS error.... I added a function to allow it but seens to not work, I need to do some kind of restart?
@@rodolphonetto1 You probably getting CORS because your React application is on different domain. You can try Googling something like "WordPress CORS" or something like that. Also take a look at this, maybe it can help: stackoverflow.com/questions/25702061/enable-cors-on-json-api-wordpress ... Are you trying to POST something to WP API? I never had this problem, if I just tried to read the data from the API.
What do you mean. I'm just using the slug to get the post I need. You could probably filter the data by URL, but that would not be the best way to approach it.
Post structure only contains the ID for good reasons. Imagine a react app with couple of posts. First you get post data, almost instantly then Ajax requests to that media endpoint to lazy load images. For medium scale apps that structure is amazing. I was thinking the same but is not worth it to write custom endpoint for reasons in the video but I guess the purpose of it is to introduce the api.
This was actually more intended for people that are building fully static sites with Nuxt, in my other series. Because in that case the API would never go live, and this would be an easier way to get your images and other data, there would be no lazy loading or something like that. But your point is valid, yeah.
Thanks for the tutorial! Works great! How can we use this custom endpoint to POST/update the field from postman using the same custom structure? Because ACF needs something like this: { "acf" : { "item1" : "somedescription", "item2" : "description" } } And I am hoping to POST a new item from postman without "acf", only the fields, like this: { "item1" : "somedescription", "item2" : "description" }
Try this episode, maybe that can lead you in the right direction. th-cam.com/video/_w4Ok-lI48g/w-d-xo.html But I don't know exact steps to do what you need.
The same way I showed in this video. You just need to write a custom query to get the pages and the data that you need from them. Check out my custom query series if you need help with that: th-cam.com/play/PLUBR53Dw-Ef8RvXF4iEU6UnhOlrcfIYn6.html
Not 100% sure, haven't tested it, but I think something like this should work: $data[$i]['author_name'] = get_author_meta('first_name', $post->post_author ) - check out get_author_meta docs for more information of what data you can get from it. developer.wordpress.org/reference/functions/get_the_author_meta/
If you are using ACF for custom fields, check this out, it should help you implemnt it in custom endpoint: www.advancedcustomfields.com/resources/query-posts-custom-fields/
Hello sir. It's a request. Could you please make a video on. How to integrate Rest API into WordPress.i want to fetch data from another website.full Complete video please.
Amazing! I was too lazy to read the developer docs and this video saved me.
Hehe :)
yep, straight to the point, only 5 minutes and I'm subscribed
moreover I solved my problem in 2 minutes, this channel is superb
@@iamanderson Thanks man. Glad you like the channel :)
Wow, i was looking for this information. Thank you! Grettings from Bolivia.
Thank you for this. I needed to send the output of a js function I built to an API endpoint for the app developer I am working with. This video was one of the links in the chain that I needed. I appreciate how clearly stated and demonstrated this was.
I'm glad I could help 😀
I'm a simple guy who needs simple explanations. This video was awesome, thank you!
Glad I could help. I try to make my videos as simple as possible, thanks for noticing 😀
It's a privilege to meet you all. I hope your families experience excellent health, prosperity, and plenty of good fortune.
Very use full video hidden gem for me i am creating one mobile app and i want this kind of solution thankyou so much for this sir...
Glad I could help 😀
I didn't see the video you mentioned and I'm only here to learn about custom endpoints. Surprise!! :D
Nobody saw that video 😁
Thank you for keeping it simple. I need a bit more information for my purpose but now I understand how custom endpoints work. You put me on the right track. Happy New Year!
Happy new year to you too! Glad this helped you ;)
Thank you for the tutorial! And many thanks for using a dark background editor👌, my eyes are sore from other's tutorials with light themed editors 😒😒
Thankyou, you are a great teacher, keep it up. And I like the outro music
Thanks ❤😄
Thanks for sharing this!
I'm using LearnPress plugin data to be consumed from an external web service.
Thanks!
Thank you man, watched and learnt...neat and clean!
I just subscribed, yes, because of your great content, but above all after seeing again the pic at 6:48...actually also because you didn't bore any of us with wasting time in asking us to subscribe, to ring the bell, to comment below, to pet our cat, to clean our room, etc etc...
Hvala!
(Am i right if I guess that your English is pretty amazingly Serbian?)
Thanks for watching and subscribing man :) I appreciate it. My accent is Croatian, but Serbian and Croatian are very similar languages :) so I understand why you would think that.
Great tutorial man, very useful. It makes the output of the json object so much cleaner. With custom fields, I believe I can use it to create an online task organizer.
Great 😀 thanks for watching.
Your my new teacher.
Hehe 😀 thanks for watching.
hi do you have a video for WP REST API where we can update the data? I dont see any videos regarding to that. all of the youtube videos available are just getting data
I think the lack of those videos have something to do with the authentication. It's pretty tricky to do in WP. But that is a good idea. I will see what I can do. Thanks for the suggestions.
This was so helpful. Thank you!
Nice, glad it helped 😀
I would like to ask, ermm where you got that wp-json? I'm so sorry to ask this since i'm a beginner and i don't quite understand to this topic
What do you mean exactly? URL wp-json/... comes with WP, out of the box. I don't know if that answeres your question.
@@WatchandLearnTutorials actually, i'm also not sure about that wp-json. Because most of tutorial use that to call json. But i dont know where to find it. Like where it is come from
@@nurulfarhana2773 You are going to have to be more specific with your questions, I'm not sure what you mean. And also if you are a beginner you probably don't even need this right now, this is used if you want to make your frontend with JavaScript (React, Vue, Next) or maybe provide data for mobile applications.
@@WatchandLearnTutorials ohhh okay thank you for replying me
@@nurulfarhana2773 I think that I know what you mean and I had the same issue. I'm also getting a 404 when I try to access /wp-json/wl/v1/posts.
Try:
/?rest_route=/wl/v1/posts
It worked for me.
Thanks for video. How can i do with a external API. Would you help use with short video ? Thanks again.
Thank you, that is what I am looking for) how to make it only for authorized people? And get his user id? I want to save user data to the database
Uff me has ayudado un montón, gracias!
Glad I could help 😁
One question the same structure works if we are talking about woocommerce?
I believe that you could make custom endpoints for WooCommerce. However Woo comes with it's own API, so maybe better use that: docs.woocommerce.com/document/woocommerce-rest-api/ and documentation is here: woocommerce.github.io/woocommerce-rest-api-docs/#introduction
hello, I have a question. Hove can I get (_embedded -> author-> url) for exampl: $data[$i]['_embedded']['author'] = ...? Thanks.
where are you setting "/wp-json/wl" please advice
I subscribed immediately you said "crushing it" ... lol
:D giphy.com/gifs/silicon-valley-siliconvalleyedit-GpvGNDIruGFQk
Good stuff thanks. I noticed how bloated the default end points are, I will use a custom one thanks to you!
Can You share which font you are using in Your Coding tool.I like it and How to I set it in my VS code
I think it's Operator Mono.
Amazing ! thank you bro. this tutorial was awesome !
Thanks, glad I could help :) Check out the two latest videos on the channel also, they are part 2 and part 3 of this video.
This video is very helpful and to the point. Thank you.
Glad it was helpful and thanks for watching 😃
Thanks, but how can I get my custom taxonomies, usually recieved them by 'get_field()' method, but in the plugin wl-api it doesn't work. Please, help, if you know.
Isn't get_field() an ACF function? Are you defining your taxonomies with ACF? If not, then this not the function you should be using. Also take a look at these videos: th-cam.com/video/76sJL9fd12Y/w-d-xo.html , th-cam.com/video/5rSfAkLO5eo/w-d-xo.html maybe you get the idea from there. You can use WP_Query to get pretty much anything from WP. I also have a whole series about it, so you can also take a look at that: th-cam.com/play/PLUBR53Dw-Ef8RvXF4iEU6UnhOlrcfIYn6.html
Thanks it was really helpful
Glad to hear it :D
This is great, but after implementing it seems paging no longer works by using: ?page=X... any suggestions?
You need to handle pagination yourself, by using something like WP_Query it has pagination built in. You would use that instead of get_posts. I can't explain the entire process in the comment. Maybe I will make a video about it.
@@WatchandLearnTutorials That would be amazing!
How can we detect installed plugins and theme info
You can use developer.wordpress.org/reference/functions/wp_get_theme/ for getting the theme and probably developer.wordpress.org/reference/functions/get_plugins/ for getting the plugins. Never used those two functions but I hope they will work.
@@WatchandLearnTutorials thanks
thanks, and love the way you taking
Thanks man! Glad you liked the video ;)
Thank you for this wonderful project but Is it only exclusive to WordPress or can be use in other website.
Useful one... thank you...
Glad I could help 😀
Odlican tutorijal!
What font do you have that makes the comments and keywords cursive like that? I love it!
Operator Mono
sorry for asking that,but where did you store this file on wordpress and how you did that I'm confused it's noob question but I'm noob too
It's explained from 02:00 . You create a plugin in your plugins directory of the WordPress installation.
@@WatchandLearnTutorials thank you I used WordPress one time only and it was in AWS lightsail VM , I now understand from you we going to install something on our device with folders in real WordPress is am right.
@@CodeMastersChannel Yup, we are doing this on our local machine. But after that you can just upload those files to your hosting.
Thank. so i have one problem if i want to display all my content but only four elements i seen but i have more than four element sory for my bad english
I don't understand your question.
4:45 thanks for "awesome endpoint" how could i return a html-file ? i tried an then just it returns just FALSE.
You can't return HTML file. That is not what the REST API is for. You can only return JSON data, like shown in the video.
And another way too return html by reading the url? May so? : function cathy_plugin_demo_filter_content($content) if (isset($_GET['pups'])) $content = 'huhu';
@@absolutelynothing6324 You can return the content (with html tags) of the post as an object property, yes. That is how default API endopoints work.
how can you do for custom tables?
Simple and clear, thank you :-)
is it possible to explain how to add custom fields to the custom route? seem it has special behavior.
I'm using advanced custom fields and this line helped me return their value through the API:
$data[$i]['acf'] = get_fields($post->ID);
@@andrinsuter6403 Perfect, Its worked like charm. Please is possible to advise me how to show the Categories, tags and its sub values?
@@notetomgaming6701 sorry no idea... This is literally my first WP project
@@notetomgaming6701 I will make a few videos about this soon. There has been a surge in WP Custom Endpoint questions, so I will expand on it a bit with a few more video examples.
Thank you alot for such great efforts.
Your channel already convinced me to change my way of thinking.
Good luck.
Hi thanks for your video! I'm looking for a way to disable Rest API for a user role called 'external_user'.
This user role can see right now alot of posts and pages information with when we put wp-json on the URL (users, pages, posts...)
I use actually the plugin DISABLE REST API but it prevent only not logged users to see json informations. i need to do the same thing with external_user role.
If it's not possible, can I redirect this user role (and only external_user role) to 404 pages if we try to put an URL with wp-json ?
Thanks.
I have no idea. Sorry. You need to Google that.
Thank you. Loved it
Glad you loved it 😃 thanks for watching 👍
When I try it, it returns empty array and not returning post data. Why?
I don't know. You need to provide more information for me to be able to help you.
Very nice and easy.
That's hopeful thank you so much 👍👍👍👍👍👍🌟
Glad I could help ;)
Please tell me that font name being used in the editor, I really love that font to be on my Sublime text, if supported
It's Operator Mono.
@@WatchandLearnTutorials Thank you so much :)
Great video!
Thanks man 😃
How do you add pagination here?
You don't. You handle pagination on the frontend, however, you can needed data to this endpoint if you want, something like number_of_posts, number_of_pages etc. Default routes already send that data in the response header, so maybe custom end points do the same, I'm not sure. Check this video to see what I mean, I create pagination here on frontend with Svelte: th-cam.com/video/eKHoFSVyRV0/w-d-xo.html
good lesson
this is awesome video ...but if I wanna categories data so how can i define that...(Menus url ) page data how can I fetch that data
You would have to learn some basics of PHP and how WordPress loop works, and also how WordPress custom queries work. I have a playlist for WP custom query so you can check that out: th-cam.com/play/PLUBR53Dw-Ef8RvXF4iEU6UnhOlrcfIYn6.html ... But before that I recommend that you get familiar with the basics of PHP.
Really good video! The speaker sounds like an Easter European selling soviet weapons on the black market “Far be it from me to question your logic, you must have your reason you want this nuclear warhead. Not my business.”
Heh :) I'm from Croatia, I'm guessing most Slavs have this kind of accent :)
Great content. Thank you!
You are welcome ;)
Hey Great Tutorial. Much needed.
I have one problem. How can I get the link/url of the current post? I am adding post_link but its not working. I want the permalink of a post or all posts.
$data['Link'] = $post[0]->post_link;
not working.
Please HELP!
Loved the explanation! Can I send audio files through the REST api? Please help
You probably can, but it's not something I can explain in a comment.
@@WatchandLearnTutorials Understandable! Could you recommend a resource or a video for the same, sir? I am literally stuck. Thanks in advance
(I have to send audio files to the Media Library & then grab & share there link on my flutter application...)
@@sameermishra3598 I don't know of any such link, sorry. But just keep this in mind, audio file is just a file, so try looking for tutorials about file upload, it doesn't matter if it's an audio, image or text document, the procedure should be the same.
First of all thank you for the video it will help me a lot
Im a kind of a newbe with php... is it dificult to get author name? since the default API gives me an ID and my host block the users endpoint for security reasons (and I think it should stay like that)
Maybe you could do it by doing something like:
$data[$i]['author'] = get_the_author_meta( 'display_name' , $post->post_author )
Maybe something like that will, work, but I haven't tested it.
@@WatchandLearnTutorials Thank you, I'll try that looking on the documentations. Now I having a problem, in the browser and postman my request works fine, on an axios request from react I receive a CORS error.... I added a function to allow it but seens to not work, I need to do some kind of restart?
@@rodolphonetto1 You probably getting CORS because your React application is on different domain. You can try Googling something like "WordPress CORS" or something like that. Also take a look at this, maybe it can help: stackoverflow.com/questions/25702061/enable-cors-on-json-api-wordpress ... Are you trying to POST something to WP API? I never had this problem, if I just tried to read the data from the API.
Hello, Thank you for the video, ¿How I can add security to this API? Happy New Year!
You could probably install CORS plugin. And there you can define what domains are able to access your API. But I'm not 100% sure.
Odlicno! Tnx!
foreach($posts, $key => $value){...} instead of $i++;
👍 Thanks.
you show slug what about URL? How to show entire URL? thanks
What do you mean. I'm just using the slug to get the post I need. You could probably filter the data by URL, but that would not be the best way to approach it.
gracias amigo!, your are the best!
Post structure only contains the ID for good reasons. Imagine a react app with couple of posts. First you get post data, almost instantly then Ajax requests to that media endpoint to lazy load images. For medium scale apps that structure is amazing. I was thinking the same but is not worth it to write custom endpoint for reasons in the video but I guess the purpose of it is to introduce the api.
This was actually more intended for people that are building fully static sites with Nuxt, in my other series. Because in that case the API would never go live, and this would be an easier way to get your images and other data, there would be no lazy loading or something like that. But your point is valid, yeah.
Tell me please, how do you thing? What CMS is better for creating restAPI ? WordPress or October?
You should use whatever you are comfortable with. WordPress and October both have powerful options to create the any kind of REST API that you want.
Amazing! Thank you so much
Glad I could help, thanks for watching :)
Thank you so much ❤️❤️❤️❤️
Thank you
You are welcome :)
Nice and simple COde
Thanks for the tutorial! Works great! How can we use this custom endpoint to POST/update the field from postman using the same custom structure?
Because ACF needs something like this:
{
"acf" : {
"item1" : "somedescription",
"item2" : "description"
}
}
And I am hoping to POST a new item from postman without "acf", only the fields, like this:
{
"item1" : "somedescription",
"item2" : "description"
}
Try this episode, maybe that can lead you in the right direction. th-cam.com/video/_w4Ok-lI48g/w-d-xo.html But I don't know exact steps to do what you need.
Thanks A lot Man.
Thank you for keeping it simple. how can i write custom endpoints to the pages
The same way I showed in this video. You just need to write a custom query to get the pages and the data that you need from them. Check out my custom query series if you need help with that: th-cam.com/play/PLUBR53Dw-Ef8RvXF4iEU6UnhOlrcfIYn6.html
Great Video, thanks
Please how do I include author name to custom
Not 100% sure, haven't tested it, but I think something like this should work: $data[$i]['author_name'] = get_author_meta('first_name', $post->post_author ) - check out get_author_meta docs for more information of what data you can get from it. developer.wordpress.org/reference/functions/get_the_author_meta/
Great video! And can you please explain how to filter posts by custom field from custom endpoint?
If you are using ACF for custom fields, check this out, it should help you implemnt it in custom endpoint: www.advancedcustomfields.com/resources/query-posts-custom-fields/
Hello sir. It's a request. Could you please make a video on. How to integrate Rest API into WordPress.i want to fetch data from another website.full Complete video please.
I won't make that kind of video, sorry. This is a edge case and also not something I wanna do on this channel.
Thank you!
How to secure endpoint s
Check this article out, maybe it has the info you need. www.wpwhitesecurity.com/wordpress-rest-api-and-the-security-worries/
why do i do the f* same thing in ANY tutorial and the WP does not give the endpoint?!
You probably screwed something up 😀 ... it's rarely WPs fault. What error do you get?
llike your accent are you Russian?
Thanks :) however I'm not Russian, I'm from Croatia.
Air duction 2mins 18 secs
Brother Please make a WP Woocomerce tutorial, finish your tutorial. message me i can pay if need be.
I'm not doing WooCommerce tutorial until they write better documentation for it. Sorry.
Thanks man, it's very simple now. But your PHP code.. really bad :P
Your PHP code is really bad :P
just open my home page