0

I've made a custom WordPress post and it has many fields to input. Also, I've made a custom plugin that calls the API from the other site and creates posts using the API results. The other things are working well. But in my custom posts, there's a gallery to show the thumbnail images and I can get the image urls from the API.

"Images": [
       {
        "Priority": "0",
        "Caption": "",
        "Uri": "https://images.boatsgroup.com/images/1/68/46/7376846_20200225094022955_1_XLARGE.jpg",
                        "LastModifiedDateTime": "2020-02-25T09:49:53-08:00"
        }]

enter image description here

So I've added the images manually to check where the images are saved in the database. But I am not sure.

I want to know:

  1. Where can I find the saved data for the gallery in the database?
  2. How to create posts using the image URLs from API results automatically?

If anybody has experience in this kind of problem, help me, please.

dhero
  • 11
  • 3
  • Does this answer your question? [How to expose all the ACF fields to Wordpress REST API in both pages and custom postypes](https://stackoverflow.com/questions/56473929/how-to-expose-all-the-acf-fields-to-wordpress-rest-api-in-both-pages-and-custom) – disinfor Sep 21 '21 at 19:54
  • thanks. But I think it's a little different case to me. Actually, in my customized post fields, I can set the other fields like this. ``` update_post_meta($boatId, 'BoatCityName', $value['data']['BoatLocation']['BoatCityName']); ``` – dhero Sep 22 '21 at 05:16
  • But the only thing I am not sure is the 'gallery' field. I am not sure where can I find the gallery information in the db. And how to create 'gallery' using the image urls. – dhero Sep 22 '21 at 05:24
  • The gallery field is an ACF field. The information is saved in the post_meta table. – disinfor Sep 22 '21 at 14:12
  • I thought that they will be saved in the post_meta. But I can't find it in that DB table. – dhero Sep 22 '21 at 14:42
  • That's where the data is saved, so I'm not sure why it's not for you. Here's some more information about updating as well: https://stackoverflow.com/questions/53596688/update-acf-fields-inside-layout-via-wp-api – disinfor Sep 22 '21 at 14:50
  • If possible, I want to share my codes with you. How can I contact you? – dhero Sep 22 '21 at 15:11
  • I've found the gallery info in the postmeta. You were right. And the meta_value looks like this: a:2:{i:0;s:4:"1384";i:1;s:4:"1382";} What does it mean? – dhero Sep 22 '21 at 18:19
  • that's a serialized array. I'm guessing those at the id's for the images in your gallery. – disinfor Sep 22 '21 at 18:30
  • To make the post I need to input this kind of serialization into the db. So do you have any idea to serialize like above using image urls? – dhero Sep 22 '21 at 18:38
  • use https://developer.wordpress.org/reference/functions/attachment_url_to_postid/ to get your image ids and then use PHPs `serialize` function to add it to the db. – disinfor Sep 22 '21 at 19:15
  • I think the $url in the attachment_url_to_postid( string $url ), point the url of the wordpress site located in the wp-contents. If this is the outside url, I think the above function will not work. – dhero Sep 22 '21 at 19:52
  • Yeah, that will not work. You will need to figure out how to store the data on the other site to make it work for you. – disinfor Sep 22 '21 at 20:03
  • Thanks for your comments. I will try more. If you have any ideas for this one, let me know please. – dhero Sep 22 '21 at 20:07

0 Answers0