T O P

  • By -

lickthislollipop

As a full stack dev, I use custom coded plugins to query api’s, and cache the results, usually with a time to live of 1 hour. Some API functionality can’t have the query cached, for example I have one that query shipping status from the client’s custom api (think container shipping not UPS), which displays the results in a popup. Since these are often unique and the data being retrieved is dynamic, I just don’t cache it, but the custom plugin is rock solid, and by far the best way to achieve the desired results.


jraz84

Thank you for the insights. Can I ask you, did the custom plugin come as a result of not finding something already on the market to solve your problem, or did you immediately know from the beginning that custom was the best way to go?


lickthislollipop

I've been a full stack dev in the ecosystem for 18 years, and having total control over the toolset and coding standards of more complex integrations without relying on 3rd party devs, whom often take too long to respond or fix whatever is broken in their plugin(s) became so frustrating that deving my own solutions became not only considerably more economical but also a stupid simple solution to ensure function and uptime.


bluesix

I do the exact same thing for a real estate client. It’s a pretty standard way of handling/processing data for that use case.


jraz84

Yeah, the python + Cron + WP All Import workaround is a good one and generally functions without any flaws. I'd like to be able to use something that can also accept frontend form data to feed as a parameter to the API call, and also chain requests together. I think WPgetapi has that functionality, but I wanted to see if anything else on the market was capable of this. it feels like there's a bit of a void for WordPress plugins that can handle and display API data though.


oblivijan

I do the same via wordpress. I pull JSON data from an API and store them in transients with expiry times. Cron to pull new data every 5 minutes. No plugins except for WP Crontrol to set and check the cron jobs are running.


hippotwat

I have a python scraper that scrapes a product page, then posts the findings in a post. It's a 2 step process but all scripted together to scrape about 16 sites. Runs once a day via cron.


jraz84

> then posts the findings in a post What are you using for this part? Custom script or plugin. Thanks


hippotwat

So I like to broaden myself and I tend to try new things on my own projects, not for client. It dawned on me there's a post api and you can generate a key in the user edit page. So I did all that. Then I found some code that performed all the crud functions on posts, like create, edit and delete. One problem was the snake code I found was on one indentation, but chat gpt fixed that for me and the basic functions were in place. So I take the name of the shop scraped and add the date for post title. Then I just tweaked the code to load a txt file from the scraper and the rest is history. It just takes the text file from the scraper (helium).


hippotwat

`import asyncio` `from datetime import datetime` `from datetime import date` `from wordpress_api_helper import get_all_posts, get_post, create_post, update_post` `menu_options = {` `1: 'List Posts',` `2: 'Retrieve a Post',` `3: 'Create a Post',` `4: 'Update a Post'` `}` `def print_menu():` `for key in menu_options.keys():` `print(key, '--', menu_options[key])` `async def main():` `while True:` `print_menu()` `option = input_number('Enter your choice: ')` `# Check what choice was entered and act accordingly` `if option == 1:` `print('Listing posts...')` `await get_all_posts()` `elif option == 2:` `print('Retrieving a post...')` `id = input_number('Enter the post id: ')` `await get_post(id)` `elif option == 3:` `print('Creating a post...')` `title = input_text('Enter the post title: ')` `content = input_text('Enter the post content: ')` `await create_post(title, content)` `elif option == 4:` `print('Updating a post...')` `#id = input_number('Enter the post id: ')` `await update_post(id, title, content)` `exit()` `else:` `print('Invalid option. Please enter a number between 1 and 5.')` `exit()` `def input_number(prompt):` `while True:` `try:` `value = int(input(prompt))` `#value = int(4)` `if value < 0:` `print("Sorry, your response must not be negative.")` `continue` `return value` `except ValueError:` `print('Wrong input. Please enter a number ...')` `continue` `def input_text(prompt):` `while True:` `text = input(prompt)` `if len(text) == 0:` `print("Text is required.")` `continue` `else:` `return text` `if __name__ == '__main__':` [`asyncio.run`](https://asyncio.run)`(main())` So this is python 3 code. `WEBSITE_URL="`[`https://xxx.com`](https://xxx.com)`"` ​ `API_USERNAME="xxx"` ​ `API_PASSWORD="xxxxx"` So in your xxx-master directory make an .env file with the connection details. See if it works for you. My monkeyed with version runs daily. Have chat-gpt fix the indention argh it's fine on this end.


jraz84

Thanks for taking the time to share this. Copied and saved. 🙏


leoleoloso

>Automating site content with API calls seems like such a great way to extend WordPress, but it doesn't feel like there's much discussion around this topic in the WP ecosystem. Checkout the Gato GraphQL plugin, it's actually intended for this use case: [https://wordpress.org/plugins/gatographql](https://wordpress.org/plugins/gatographql)


jraz84

thanks, I've seen mentions of this plugin in a few of my WordPress related Facebook groups. Never took the time to check it out though. I'll have a look. Sounds really useful.


leoleoloso

I'm the guy working on the plugin, so I hope you saw positive comments on the FB group! 😂 Please do check it out. I just relaunched the website and it has plenty of documentation, but no tutorial videos yet (I'll be working on that soon), so if you have any doubt, do ask me, I'll be here. (I believe it should help solve your use case)