Extend WordPress REST API :: Add Fields to Posts Endpoint

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

TechiePress

TechiePress

Күн бұрын

Пікірлер: 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 М.
Дарю Самокат Скейтеру !
00:42
Vlad Samokatchik
Рет қаралды 1,9 МЛН
1❤️
00:17
Nonomen ノノメン
Рет қаралды 13 МЛН
Querying external APIs with XML data using WordPress
18:18
TechiePress
Рет қаралды 2,2 М.
Display WordPress API XML Queried data on front end with AJAX
28:49
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 М.
ПОКУПКА ТЕЛЕФОНА С АВИТО?🤭
1:00
Корнеич
Рет қаралды 3,7 МЛН
Samsung Galaxy Unpacked July 2024: Official Replay
1:8:53
Samsung
Рет қаралды 23 МЛН
Easy Art with AR Drawing App - Step by step for Beginners
0:27
Melli Art School
Рет қаралды 9 МЛН
Спутниковый телефон #обзор #товары
0:35
Product show
Рет қаралды 2,2 МЛН
Первый обзор Galaxy Z Fold 6
12:23
Rozetked
Рет қаралды 379 М.