WP JSON to Google Sheets – Reflective Data

Image from page 86 of “Refraction and motility of the eye, with chapters on color blindness and the field of vision” (1920) flickr photo by Internet Archive Book Images shared with no copyright restriction (Flickr Commons) Way back in 2015, I wrote a little plugin1 to count URLs, get the word count and do other stuff so I could reflect on my blog posts. Given some (k)new knowledge2, I figured I could make a version that runs in Google Sheets and indeed I can. The reason I like this as an alternative to the plugin is that it works for anyone who has access to Google Sheets even if they can’t install plugins. Google Sheets also offers a lower barrier to messing with your own data once you get start capturing it. You can count the !s, or a variety of emoticons, or how often you use the word “spaces,” or whatever you want- all without the ability to program in php or javascript. I think it starts to open up different doors for students3 to gather their own kind of data for reflection and amusement. It starts to get at the DIY ethos inherent in the quantified self communities. The sheet is here. I’m going to build it out into something a bit more robust and plug/play in the […]

WP REST API Custom Fields to Google Maps

Manuel, the young shrimp-picker, five years old, and a mountain of child-labor oyster shells behind him. He worked last year. Understands not a word of English. Dunbar, Lopez, Dukate Company. Location: Biloxi, Mississippi. (LOC) flickr photo by The Library of Congress shared with no copyright restriction (Flickr Commons) 1 I had a site we used for the Great VCU Bike Race course that’s been sitting around. I knew it had lat/lng data for lots of urban bicycle related posts. My goal was to get it into Google Maps via the REST API. Get Custom Field in JSON By default you won’t see custom field data in your JSON endpoints. There are some plugins to make that happen but I wanted to take a stab at doing it myself. Given the documentation, it was pretty trivial.2 The code below in a plugin or the function.php file would make the lat_long custom field show up in the post JSON. Using this URL, I can get the 30 most recent posts.3 Some Map Stuff Google wants lat/lng separate but it’s coming in as one item split by a comma. These little functions split it up nicely. In javascript, split breaks up a string by the defined element (comma in this case) and returns the pieces as an array. Since I’ll get two pieces […]

Vue and the WordPress REST API

I’ve continued to play around with using Vue and WordPress’s API. The Vue stuff is entirely new to me but it’s pushing my javascript knowledge. The main reason I’m excited about the WordPress/Vue (or whatever framework) combinations is simply speed. If you have any doubts give the pagination at the bottom of this demo site a shot. Crazy fast . . . and running stock on shared hosting. No caching plugins etc. The site is running the Vuetiful WordPress theme which has been an interesting thing to look at and see how it all works. Github is such a good thing. Below or linked here is the WP JSON/Vue pagination I eventually got working. It’s forked from this demo by Brian Krosgard.1 Even with that large head start, a few things hung me up. First, the navigation of the JSON elements is a bit tricky if you’re not used to it. You’ll want to use the _embed parameter2 to get access to the featured image data. That’s an option I didn’t know about previously. https://anth101.com/wp-json/wp/v2/posts?_embed&per_page=24&page=1 Since I named my main JSON objects ‘post’– to access the thumbnail URL, I’d use post._embedded[‘wp:featuredmedia’][0].media_details.sizes.thumbnail.source_url The part you need to pay attention to is the square brackets and the number following it. Notice there is no period between _embedded and [‘wp:featuredmedia’]. You might also […]