Extend WordPress REST API :: Add Fields to Posts Endpoint

  Рет қаралды 3,792

TechiePress

TechiePress

Күн бұрын

In this video, learn how to Add Fields to Posts Endpoint to Extend WordPress REST API the default endpoint to serve more server side rendered data to your external application.
00:00 Challenge Introduction
00:51 Explaining the challenge
01:17 Expounding REST API Endpoints
02:18 Why WordPress as Headless CMS
03:55 Coding the REST API Endpoints plugin
06:55 Register REST API fields
09:26 Add Featured Image to the Endpoint
13:24 Add Author Name to Endpoint
14:35 Add Author Description to Endpoint
Leave any questions in the comment section.
Code sample: github.com/yttechiepress/exte...
=============================================
Do you like what I am doing? You can buy me a coffee through PayPal: paypal.me/laurencebahiirwa
Or purchasing through my Plugin Affiliate links:
==== To Get a Domain and WebHosting ====
- Web Hosting with Bluehost ---- omukiguy.com/bluehost
- Web Hosting with Hostgator ---- omukiguy.com/hostgator
==== Use simple Build Website Tools ====
- Elementor Pro ------ omukiguy.com/elementor
- Crocoblock ----------- omukiguy.com/crocoblock
- Woo Feed Pro ------- omukiguy.com/webappick/
- Woo Invoice Pro ---- omukiguy.com/webappick/
I am social too:
Facebook: / techiepress-1001496550...
Twitter: / omukiguy
Blog: omukiguy.com
GitHub: github.com/Omukiguy
-------------------------------------------------------------------------------
LEARN MORE IN THE WELL CURATED PLAYLISTS BELOW
--------------------------------------------------------------------------------
Learn how to build a plugin from scratch: • Plugins Vs Functions.p...
WooCommerce E-Commerce customizations
== Build Free Custom E-commerce Online Shop using WooCommerce - • WooCommerce customizat...
== Build Free Custom Theme for E-commerce Online Shop using WooCommerce -
• Woocommerce Restaurant...
====== Build Dynamic Websites with Elementor ======
== Learn the Elementor basics - • Elementor Beginner Tut...
== Build a custom Elementor Widget from Scratch - • Build Custom Elementor...
====== How to use WordPress Gutenberg Block Editor ======
WordPress 5.4 Gutenberg Blocks Updates
== • WordPress 5.4 Gutenber...
WordPress Gutenberg blocks for Designers
== • WordPress Basics Train...
Gutenberg WordPress Block Editor tutorials for beginners
== • WordPress Basics Train...
Custom WooCommerce Gateway Development from Scratch
== • Build Custom WooCommer...
WordPress Custom REST API Namespaces, Endpoints and Examples from Scratch
== • Create Custom WordPres...
====== WordPress Plugin Development from Scratch ======
Build Most Popular & Most Commented Post Plugin
== • Build WordPress Most P...
Build SMS Plugin with External WordPress API Integration using custom WordPress Databases
== • Build SMS Plugin - Ext...
WordPress External APIs Integration Plugin Development
== • WordPress External API...
Convert WordPress to mobile App in Headless WordPress
== Convert WordPress Sports Website into Mobile Application - kzbin.info?list...
Make GraphQL API endpoints with WordPress Headless CMS WPGraphQL Plugin
== • Make GraphQL API endpo...
Customize Your WordPress & ClassicPress
== Build Custom REST API Endpoints with WordPress or ClassicPress - • Build Custom REST API ...
Custom Dashboard Widgets
== • Custom Dashboard Widge...
Build Custom Admin
== • Custom Admin for WordP...
Learn Git
== Git tutorial for writers + software developers for beginners - • Git tutorial for begin...

Пікірлер: 25
@terrycarson
@terrycarson 4 күн бұрын
No Git info anymore?
@volkan9964
@volkan9964 3 жыл бұрын
Hello, I really love this working on something and wanted to utilise the same approach to extend woocommerce's API, cureently I am stuck and was wondering if you can help me think it through.
@TechiePress
@TechiePress 3 жыл бұрын
Reach out via Web@mediauganda.com with some details and we can work something out
@ltonchis1245
@ltonchis1245 2 жыл бұрын
Great videos! Question: is it possible to Update meta field and then trigger code? 🤔😮😂
@TechiePress
@TechiePress 2 жыл бұрын
Yeah, it’s possible. Just need to get the logic right. If you save it via the editor, use the save_post hook.
@jyotibarasker2792
@jyotibarasker2792 2 жыл бұрын
Your video is excellent. Right now we are going to use Wordpress as headless cms and angular for the front end my query is how we can display the post view, likes and comment on the angular front end which updated post view, likes and comment from the angular frontend on the Wordpress backend. Can you please help me and give me some idea how we can achieve this?
@TechiePress
@TechiePress 2 жыл бұрын
You will need to create an endpoint that stores a meta field on each post. Then use angular to do the like button click and send the data over http to save in the post meta. Then you can call that meta field in the display on the front end headless. Using something like WPGraphQL might be the best option
@alexdabruh
@alexdabruh Жыл бұрын
This is super helpful, but can this way be use to trigger a wp_mail or php mail call? I embedded a react app for my client’s website with a form submission component that I will like to generate an email after each submission
@TechiePress
@TechiePress Жыл бұрын
Yes, absolutely
@TORMENTUMM
@TORMENTUMM Жыл бұрын
I want to extend the api but to make post and get requests for CRUD operations on the wordpress database. How could I do it?
@TechiePress
@TechiePress Жыл бұрын
You can make CRUD functionality in the callback function that you pass to the endpoints. That will work just fine. If you need some crud examples, I do some stuff here kzbin.info/aero/PLNqG1qGUllk0Ov_KPxypiZ-4ZzwW5pyPz
@kyraex4414
@kyraex4414 Жыл бұрын
Can this be written in code snippet?
@TechiePress
@TechiePress Жыл бұрын
Yes. Just add the ice to your snippet handing plugin and you are good to go
@Gigabyteserviceofficial
@Gigabyteserviceofficial 3 жыл бұрын
so it can handle all CRUD operations?
@TechiePress
@TechiePress 3 жыл бұрын
Yes it can.
@Gigabyteserviceofficial
@Gigabyteserviceofficial 3 жыл бұрын
@@TechiePress where we can define 'post_type' => 'our-custom-post-type' if we want to do samething for custom post type
@TechiePress
@TechiePress 3 жыл бұрын
At the same line. Just change the post_type post to your custom post type. So you would have something like 'post_type' => 'custom_post_type_name'
@Gigabyteserviceofficial
@Gigabyteserviceofficial 3 жыл бұрын
@@TechiePress THANKS am I right? register_rest_field( 'jit_image', // my custom post type is jits_image 'my_custom_field_for_custom_post_type', array(..........
@Gigabyteserviceofficial
@Gigabyteserviceofficial 3 жыл бұрын
@@TechiePress let's supposed my call back function is jit_image() then how to add offset to custom post type in wordpress api register_rest_route('jit/v1', 'media', [ 'methods' => 'POST', 'callback' => 'jit_images', 'permission_callback' => function() { return current_user_can('edit_posts'); } ]); function jit_images() { $args = [ 'numberposts' => 99999, 'post_type' => 'jit_image' ]; $posts = get_posts($args); $data = []; $i = 0; foreach($posts as $post) { $data[$i]['image']['thumbnail'] = get_the_post_thumbnail_url($post->ID, 'thumbnail'); $data[$i]['image']['medium'] = get_the_post_thumbnail_url($post->ID, 'medium'); $data[$i]['image']['large'] = get_the_post_thumbnail_url($post->ID, 'large'); $i++; } return $data; I want to allow my client-side app to fetch all custom posts but by pagination meaning offset = 10 so in each request, they will get 10 post's data not all 1000 data otherwise I think Mysq will take lots of loads. Please also share how to send requests e.g in postman like what should I include into a header or in the body as JSON data to get new 10 posts on each request.
@TestTest-hk9oh
@TestTest-hk9oh 2 жыл бұрын
Your video is excellent. Right now we are going to use Wordpress as headless cms and angular for the front end my query is how we can display the post view, likes and comment on the angular front end which updated post view, likes and comment from the angular frontend on the Wordpress backend. Can you please help me and give me some idea how we can achieve this?
@TechiePress
@TechiePress 2 жыл бұрын
You will need to create an endpoint that stores a meta field on each post. Then use angular to do the like button click and send the data over http to save in the post meta. Then you can call that meta field in the display on the front end headless.
WordPress REST API + Ajax for Secure External API Data
31:10
TechiePress
Рет қаралды 8 М.
Querying external APIs with XML data using WordPress
18:18
TechiePress
Рет қаралды 2,2 М.
HOW DID HE WIN? 😱
00:33
Topper Guild
Рет қаралды 40 МЛН
DO YOU HAVE FRIENDS LIKE THIS?
00:17
dednahype
Рет қаралды 89 МЛН
Want to make a video chat app? Watch this video for WebRTC!
1:22:35
Good Morning Developers
Рет қаралды 25 М.
Deep Dive into REST API Design and Implementation Best Practices
12:02
Software Developer Diaries
Рет қаралды 40 М.
PHP Debug External API data Query in WordPress
13:19
TechiePress
Рет қаралды 2,4 М.
Web Development In 2024 - A Practical Guide
2:43:32
Traversy Media
Рет қаралды 369 М.
iPhone 15 Pro в реальной жизни
24:07
HUDAKOV
Рет қаралды 167 М.
Опыт использования Мини ПК от TECNO
1:00
Андронет
Рет қаралды 756 М.
Хотела заскамить на Айфон!😱📱(@gertieinar)
0:21
Взрывная История
Рет қаралды 6 МЛН
Samsung Galaxy Unpacked July 2024: Official Replay
1:8:53
Samsung
Рет қаралды 23 МЛН