Help

Re: Airfields, a Wordpress plugin for managing custom fields in Airtable

2285 2
cancel
Showing results for 
Search instead for 
Did you mean: 

If you run a Wordpress website and you want to be able to easily pull data from Airtable into Wordpress, this is for you.

Airfields is a Wordpress plugin I’ve built that allows data from Airtable to be accessed using Wordpress’ get_post_meta and get_post_custom functions. There is also a shortcode you can use in the post editor that will output the value of whatever Airtable field you specify.

The way it works is that in the Airfields admin settings you will provide (App ID, API Key and) the name of an Airtable table and a field from that table in which either the post slug or the post ID will be stored. Then, any posts that match will have its custom data populated from the fields of the corresponding record from Airtable. This works with pages, posts, and any custom post type and can be used to display any field type Airtable supports.

This should be considered a beta. If you’re a Wordpress plugin developer interested in helping develop this plugin, let me know. And if you’re interested in testing out the plugin, go for it and let me know what changes you’d like to see.

https://github.com/chetmac/airfields/

Here’s what editing a page using shortcodes looks like:
9833d5f1102943f62d6c2e06b909a844ee77e262.png

Here’s the output on the website:
38322647b7fbadd1df06b788ae47052ff30c2a44.png

Here’s the Base it pulls from:
Pasted image

Here’s a code sample of how to use Airfields inside a PHP template file (the Airtable field as actually named, ‘Attachement’):

<?php
$attachment = get_post_meta($post->ID,"Attachment");
echo "<img src='".$attachment[0]["thumbnails"]["large"]["url"]."'>";
?>
17 Replies 17
Devin_Balkind
6 - Interface Innovator
6 - Interface Innovator

Very happy to see this type of functionality emerge. Trying to test it out now but can’t find the Airtable “App ID”. What is that?

Visit https://airtable.com/api and select the Airtable Base in question.

Then look in the address bar of your browser and you’ll see something like:
https://airtable.com/appaw53I4abVTeqVn/api/docs#curl/introduction

The App ID is the portion of the URL that begins with “app” and ends prior to the next front slash. So this App ID would be appaw53I4abVTeqVn

You could also look in the right-hand pane of that same page to find it:
7384ae3cd870a2260ced023c91061bc3f7c423aa.png

It’s the portion between https://api.airtable.com/v0/ and the name of the Airtable Table.

Devin_Balkind
6 - Interface Innovator
6 - Interface Innovator

Great. That worked. The settings page seems to register everything appropriately.

When trying to use the short code though I don’t get any results.

I added the code as described.

Airtable column that I want to appear is “Tools”.

I put the following text in a post:

Name: [airfield name=“Tools”]

When I publish and view, the only words on the page are "Name: "

For anyone else that might come across this, the solution was to append ?fresh=true to the page URL to force a fresh “fetch” from Airtable.

It’s true. Works great. Very interesting plugin with lots of possible uses.

One thing I noticed however is that, for fields that are linked to other AirTable sheets, it prints out a code instead of the value.

Ex.
AirTable Tools Type: Software
WordPress display of Tool Type: recrpNJrVHp0ioect

Can anything be done to display the value instead of the code?

At present, you’d need to create a Lookup field in Airtable that actually displays the value you want. Then reference that field in the Wordpress shortcode.

In the future, there will be an option/setting in Airfields that will allow you to specify Wordpress filters on each field that could do things like: retrieve associated records, merge two date records into a single duration, etc.

The biggest roadblock I’ve found as I’ve attempted to make my code “user friendly” via a plugin is displaying multiple linked records easily. For my projects, I’ve introduced a shortcode that includes an entire PHP file instead of simply outputting the field value. This allows me to loop, show defaults, and execute other logic on the field value before producing output.

This looks super cool. Thank you.

Stuart_Brameld
6 - Interface Innovator
6 - Interface Innovator

Awesome, really pleased to see this, it this makes so much sense!

Great job!

I have a client project that could be a good fit for this, and we work with lots of Wordpress developers that could help out, hence may be in touch in the next month or so.

Thanks for the feedback. Please do reach out. I’ve developed this much farther as straight code—this plugin is my attempt to make it more abstract and universally useful via admin settings.

Great, will do. Thanks Chester.

John_Beaudoin
7 - App Architect
7 - App Architect

Chester,

Thanks for sharing this! It might be really helpful to a project I’m working on. I have three questions for you:
[1] Is there any way to get the plugin to return multiple values from the lookup field – or is this what you meant when you said the biggest challenge was “displaying multiple linked records easily”? Right now, it only seems to return the first value of the lookup field.
[2] Do you know of a way (in Wordpress) to automate the appending of the “?fresh-true” to each post (for instance, it doesn’t appear you can add it to the post’s permalink through the standard editing UI)?
[3] Is there any way to make the plug-in case insensitive when matching the post name to the Airtable record identifier? My WP page slug is all lower case (e.g. john or susan), but the Airtable record is upper case. If not, I can transform the record in Airtable to all lower case, so it’s not a big deal…
Thanks again. Very promising work!

Good news and bad news :slightly_smiling_face:

I’m completely rebuilding Airfields to accommodate all these, the bad news is that I’m in the middle of it so it’s not done.

I will definitely post here when it’s ready.

I’m happy to say that I’ve just posted the completely rebuilt Airpress to GitHub. The plugin used to be called Airfields but I have grander aspirations for the plugin now, so I needed a grander name. The goal is to be able to augment every aspect of Wordpress using Airtable data—hence Airpress.

Currently, posts/pages can automatically fetch corresponding Airtable records. Or “virtual” posts/pages can be created from corresponding Airtable records. And related records can easily be fetched.

I debated whether or not I should release it as beta with incomplete documentation, however I could spend another three months tweaking and improving things and I’d love to get some real-world feedback (other than from my own real-world use) and ideally find some developers willing to contribute to the project.

Russell_Myers
4 - Data Explorer
4 - Data Explorer

Any way to update a field within Airtable from a front-end form (html/PHP cURL via the API or this plugin) at the moment?

Yes. It absolutely possible, I’m doing it on a couple of client websites. However, it’s a fairly custom process depending on what you want to update and how validation needs to be carried out.

What exactly are you trying to accomplish?

One solution I’ve used in the past is to embed a form from a form provider with webhooks (Jotform or Wufoo come to mind) and I use the webhook to update Airtable. The benefit of this is having a pro form with solid validation—and all your results are still stored with the form provider as a backup.

Hay Chester, thanks for the reply.

Actually, I think moving away from Airtable and to a mySQL DB is probably the way forward for this particular case. I have a WP site which I would like to have logged in users update tables of info. Obviously this can be achieved with HTML forms and PHP to the DB but I thought perhaps Airtable and it’s API might be quicker.

Actually, I realise this isn’t what Airtable is designed for and thus probably not right for my use.

Right now, I have a form (from Airtable) embedded in a WP page. This works just fine and people can create entries in the DB. At some later point, fields within that data will need to be changed by front end users and so planned to create a front end html form to collect the data to be changed and use PHP cURL to update the Airtables through the API.

I got this working as far as fetching data and adding new records (neither of which I want to do really!) but updating an existing record using the patch method eludes me for now.

Appreciate the reply though.

Yup, totally agree with your assessment. As great as the API is, I’ve found that Airtable’s strength still lies in it’s user interface. And any projects that use Airtable, but don’t depend on the UI for some critical aspect are much better served with a local data storage solution.