Querying Wicked Folders

I was using Happy Files for many sites, but the lack of updates (a new beta was released yesterday after 28 months) and Wicked Folder Pro‘s dynamic folder features made the latter more suitable for my use.

Fortunately, querying the folder system is easy because it is just a taxonomy, so you only need the taxonomy name, wf_attachment_folders for Wicked Folders. Here is the basic query:

$query_args = [
  'post_type'      => 'attachment',
  'post_status'    => 'inherit',
  'post_mime_type' => 'image',
  'posts_per_page' => $count ?? -1,
  'orderby'        => 'date',
  'order'          => 'DESC',
  'tax_query'      => [
  [
      'taxonomy' => 'wf_attachment_folders',
      'field'    => 'slug',
      'terms'    => $cat ?? 'my-photos',
    ],
  ],
];

This is the same syntax, even if your folder structure uses subfolders. In the example above, my-photos is in a parent “folder” with a slug of stock-photos. Setting the slug to be the parent will include all of the images in any “subfolders.”

Note: the normal item.image.id for the dynamic image is not used for an attachment; it is simply item.id.

    Leave a Reply

    Your email address will not be published. Required fields are marked *