I was working on Gallery Casale and was originally just pulling in the latest post featured images, which was nice enough, but I wanted a few more options. W…

I was working on Gallery Casale and was originally just pulling in the latest post featured images, which was nice enough, but I wanted a few more options. When using Bricks, I used the API query feature to retrieve images from my Flickr account, but I wanted to see if it was possible to use Etch instead. A couple of people had done work getting other JSON data into Etch, so I borrowed their ideas and the Flickr API documentation (a challenging resource) to build my prompt for ChatGPT. It only took a couple of reworks, and I now have a way to populate the latest images and a specific album.

I opted not to make this a plugin, since the API query functionality is considered a high priority.

The latest images

I use WPCodeBox for this. Once you add it, configure your API Key and user ID, then go to [your-website-url]/wp-admin/?fw_flickr_sync=1 while logged in as the admin. This will initiate the data and set a CRON job to run hourly.

<?php
/**
 * Flickr → Etch Loop Library Sync (WPCodeBox-safe)
 * Writes/updates a Loop Library entry in the `etch_loops` option.
 */

if (!defined('ABSPATH')) exit;

/** ====== CONFIG (edit API key and USER ID) ====== */
define('FW_FLICKR_API_KEY',  'PUT_YOUR_FLICKR_API_KEY_HERE');
define('FW_FLICKR_USER_ID',  'PUT YOUR UNDER ID HERE');

define('FW_LOOP_SLUG',       'fw-flickr-feed'); // internal array key in etch_loops
define('FW_LOOP_KEY',        'fw_flickr_feed'); // Etch loop key (underscores only)

define('FW_PER_PAGE',        48);

define('FW_CRON_HOOK',       'fw_flickr_to_etch_sync');
define('FW_LAST_UPLOAD_OPT', 'fw_flickr_last_upload_ts');

/**
 * Ensure cron is scheduled (WPCodeBox doesn't have activation hooks).
 */
add_action('init', function () , 5);

/**
 * Manual run: /wp-admin/?fw_flickr_sync=1 (admins only)
 */
add_action('admin_init', function () );

add_action(FW_CRON_HOOK, function () );

/**
 * Sync Flickr → etch_loops.
 */
function fw_flickr_sync_to_etch($force_full = false)  else 

  // Merge: new first, then existing; de-dupe by id
  $merged = array();
  $seen = array();

  foreach (array_merge($new_items, $existing) as $it) 

  // Sort newest first
  usort($merged, function ($a, $b) );

  // Your rule:
  // - if > PER_PAGE: trim to latest PER_PAGE
  // - else: keep all (do not erase while still filling)
  if (count($merged) > (int) FW_PER_PAGE) 

  $entry = array(
    'name'   => 'Flickr Feed',
    'key'    => FW_LOOP_KEY,
    'global' => true,
    'config' => array(
      'type' => 'json',
      'data' => $merged,
    ),
  );

  // Only write if changed
  $current = get_option('etch_loops');
  $current_entry = (is_array($current) && isset($current[FW_LOOP_SLUG])) ? $current[FW_LOOP_SLUG] : null;

  if (maybe_serialize($current_entry) !== maybe_serialize($entry)) 

  update_option(FW_LAST_UPLOAD_OPT, $max_upload, false);


/**
 * Fetch one page of public photos and normalize.
 */
function fw_flickr_fetch_public_photos_page($page, $per_page, $extras) 

/**
 * Normalize one Flickr photo record to your Etch JSON item shape.
 */
function fw_flickr_normalize_photo($p) 
<?php
/**
 * Flickr → Etch Loop Library Sync (WPCodeBox-safe)
 * Writes/updates a Loop Library entry in the `etch_loops` option.
 */

if (!defined('ABSPATH')) exit;

/** ====== CONFIG (edit API key and USER ID) ====== */
define('FW_FLICKR_API_KEY',  'PUT_YOUR_FLICKR_API_KEY_HERE');
define('FW_FLICKR_USER_ID',  'PUT YOUR UNDER ID HERE');

define('FW_LOOP_SLUG',       'fw-flickr-feed'); // internal array key in etch_loops
define('FW_LOOP_KEY',        'fw_flickr_feed'); // Etch loop key (underscores only)

define('FW_PER_PAGE',        48);

define('FW_CRON_HOOK',       'fw_flickr_to_etch_sync');
define('FW_LAST_UPLOAD_OPT', 'fw_flickr_last_upload_ts');

/**
 * Ensure cron is scheduled (WPCodeBox doesn't have activation hooks).
 */
add_action('init', function () , 5);

/**
 * Manual run: /wp-admin/?fw_flickr_sync=1 (admins only)
 */
add_action('admin_init', function () );

add_action(FW_CRON_HOOK, function () );

/**
 * Sync Flickr → etch_loops.
 */
function fw_flickr_sync_to_etch($force_full = false)  else 

  // Merge: new first, then existing; de-dupe by id
  $merged = array();
  $seen = array();

  foreach (array_merge($new_items, $existing) as $it) 

  // Sort newest first
  usort($merged, function ($a, $b) );

  // Your rule:
  // - if > PER_PAGE: trim to latest PER_PAGE
  // - else: keep all (do not erase while still filling)
  if (count($merged) > (int) FW_PER_PAGE) 

  $entry = array(
    'name'   => 'Flickr Feed',
    'key'    => FW_LOOP_KEY,
    'global' => true,
    'config' => array(
      'type' => 'json',
      'data' => $merged,
    ),
  );

  // Only write if changed
  $current = get_option('etch_loops');
  $current_entry = (is_array($current) && isset($current[FW_LOOP_SLUG])) ? $current[FW_LOOP_SLUG] : null;

  if (maybe_serialize($current_entry) !== maybe_serialize($entry)) 

  update_option(FW_LAST_UPLOAD_OPT, $max_upload, false);


/**
 * Fetch one page of public photos and normalize.
 */
function fw_flickr_fetch_public_photos_page($page, $per_page, $extras) 

/**
 * Normalize one Flickr photo record to your Etch JSON item shape.
 */
function fw_flickr_normalize_photo($p) 

A Specific Album

The trigger for this is /wp-admin/?fw_flickr_album_sync=1. You need to add your API key, user ID, and the Album D.

<?php
/**
 * Flickr Album → Etch Loop Library Sync (WPCodeBox-safe)
 * Creates a separate Loop Library JSON entry: "Flickr Album Feed"
 */

if (!defined('ABSPATH')) exit;

/** ====== CONFIG ====== */
/** ====== CONFIG (edit API key and USER ID) ====== */
define('FW_FLICKR_API_KEY',  'PUT_YOUR_FLICKR_API_KEY_HERE');
define('FW_FLICKR_USER_ID',  'PUT YOUR UNDER ID HERE');
define('FW_FLICKR_PHOTOSET_ID', 'PUT YOUR ALBUM ID HERE'); // album id (no trailing slash)

define('FW_ALBUM_LOOP_SLUG', 'fw-flickr-album-feed');  // internal array key in etch_loops
define('FW_ALBUM_LOOP_KEY',  'fw_flickr_album_feed');  // Etch loop key (underscores only)
define('FW_ALBUM_PER_PAGE',  40);

define('FW_ALBUM_CRON_HOOK', 'fw_flickr_album_to_etch_sync');

/**
 * Ensure cron is scheduled.
 */
add_action('init', function () , 5);

/**
 * Manual run: /wp-admin/?fw_flickr_album_sync=1 (admins only)
 */
add_action('admin_init', function () );

add_action(FW_ALBUM_CRON_HOOK, function () );

function fw_flickr_album_sync_to_etch(): void 
<?php
/**
 * Flickr Album → Etch Loop Library Sync (WPCodeBox-safe)
 * Creates a separate Loop Library JSON entry: "Flickr Album Feed"
 */

if (!defined('ABSPATH')) exit;

/** ====== CONFIG ====== */
/** ====== CONFIG (edit API key and USER ID) ====== */
define('FW_FLICKR_API_KEY',  'PUT_YOUR_FLICKR_API_KEY_HERE');
define('FW_FLICKR_USER_ID',  'PUT YOUR UNDER ID HERE');
define('FW_FLICKR_PHOTOSET_ID', 'PUT YOUR ALBUM ID HERE'); // album id (no trailing slash)

define('FW_ALBUM_LOOP_SLUG', 'fw-flickr-album-feed');  // internal array key in etch_loops
define('FW_ALBUM_LOOP_KEY',  'fw_flickr_album_feed');  // Etch loop key (underscores only)
define('FW_ALBUM_PER_PAGE',  40);

define('FW_ALBUM_CRON_HOOK', 'fw_flickr_album_to_etch_sync');

/**
 * Ensure cron is scheduled.
 */
add_action('init', function () , 5);

/**
 * Manual run: /wp-admin/?fw_flickr_album_sync=1 (admins only)
 */
add_action('admin_init', function () );

add_action(FW_ALBUM_CRON_HOOK, function () );

function fw_flickr_album_sync_to_etch(): void