: Aka Morten Skoglys nerdcave

Jetpack JSON Api – outputting custom fields

januar 24th, 2017 by

Instead of using rss to retrieve data from a wordpress site I wanted to try out the Jetpack JSON API, aka WordPress Rest api. I came across some smallish challenges, so just wanted to write a quick post with the solution for those getting stuck on the same.

Problem one: The json api doesn’t display customfields as default.
Problem two: Problems retrieving data from a wordpress network (multisite)
Problem three: Weight

Problem one

We use customfields for frontpage images and to give our posts better metadata, but by default these are hidden from the public api.
To solve it, turn on Jetpack Json api, then add the following code to your WP theme functions.php:

As you can see, you have to manually add the fields you want exposed.

(Via Stackexchange)

Problem two

Error on multisite. The format to call the json api looks like this, but if you’re running a multisite install and change to then the request will fail. Luckily the solution was simple: Just urlencode the site url to (Via alpha1 on Stackexchange)

It is also possible to use the Jetpack Site ID instead of the encoded url. That ID is returned in most queries to the api, in the site_ID field. (Thanks to Jeremy Herve, via The only way to get to a subsite site_ID (as far as I have found), is to actually do the urlencode trick first.

So for this site, this will also work.

Problem three: Weight

The posts endpoint outouts (almost) all the content and data associated with your posts, which might be a bit overkill. The api actually lets you filter exactly the fields you need. Like so:,excerpt,URL,date,metadata

Which gives you a nice and tidy little JSON package:

Posted in Code

How to make the Get The Image WordPress plugin to work with TimThumb and Related posts

mars 27th, 2010 by

I’ve been using the wordpress plugin ‘Get the Image‘ by developer Justin Tadlock for a while. ‘Get the image’ does a fantastic job searching through posts looking for images, so you don’t have to add thumbnails manually, but it always bothered me that it downscaled images in the html instead of scaling and cropping them properly. I also use the lovely timThumb script on my blog, to scale, scrop and cache images on the fly, and I wanted to find a way to combine the two scripts into one.


Posted in Code, Open Source

Delicious Screenshots – my first wordpress plugin

oktober 21st, 2008 by
Warning: file_get_contents(): php_network_getaddresses: getaddrinfo failed: Name or service not known in /customers/7/5/b/ on line 75 Warning: file_get_contents( failed to open stream: php_network_getaddresses: getaddrinfo failed: Name or service not known in /customers/7/5/b/ on line 75 Warning: Invalid argument supplied for foreach() in /customers/7/5/b/ on line 79

If this works there should be about 6 thumbnails on this page, showing links bookmarked using Delicious, and tagged with «art».

Download here, version 0.7 of my very first wordpress plugin.

Activate plugin. And add your username to the options page. (under settings in the WordPress toolbar)

14.02.2017: Changed from rss to json and cleaned the code up a bit. Also removed Snapcasa from options.

What’s next:

  1. The first version of this plugin used Snapcasa for creating thumbnails, but I switched to to get a higher success rate.
  2. The count param doesn’t seem to do anything when calling the api, it always returns 10 results, so I need to handle that in the code instead. I’ve notified them of the bug.
  3. Testing other screenshotting services or making my own.
  4. Choosing an image from the page metadata when available.

Posted in Code, Open Source