18th Jul '24
/
0 comments

Post-specific HappyFiles Galleries using a Meta Box Select Field in Bricks

Post-specific HappyFiles Galleries using a Meta Box Select Field in Bricks

Updated on 19 Jul 2024

This Pro tutorial provides the steps to use Meta Box to select one or more HappyFiles' folders and output the images from the selected folder(s) using HappyFiles shortcode or Bricks' Image Gallery element or img elements in a query loop.

This is an extension of Output HappyFiles Folders in Metabox Select-Field tutorial.

Step 1

Install and activate HappyFiles.

Go to Media → Library.

Create folders and categorize images by moving them into the folders.

Step 2

Let's define a custom function that can be used to populate all the HappyFiles folder names as options of a Meta Box Select field.

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

<?php function get_happyfile_folders() { $outputChilds = true; $args = [ "taxonomy" => "happyfiles_category", //"slug" => "downloads", // get Folder by slug "orderby" => "name", "order" => "ASC", "hide_empty" => false, ]; $folders = get_terms( $args ); $selectOptions = []; foreach ( $folders as $folder ) { if ( ! $outputChilds && $folder->parent != 0 ) { continue; } $selectOptions[$folder->term_id] = $folder->name; } return $selectOptions; }

Step 3

Install and activate Meta Box.

Go to Meta Box → Custom Fields.

Create a new field group for your post type having a Select-type field.

Choices:

callback: get_happyfile_folders

If you would like to be able to select multiple folders, enable the "Multiple" option.

Step 4

Edit the posts (of your post type) and populate the field.

Step 5

Define another custom function to retrieve the IDs of images from the selected HappyFiles folder(s).

Add the following in child theme's functions.php (w/o the opening PHP tag) or a code snippets plugin:

This is a BricksLabs Pro tutorial.

For full access login below or create your BricksLabs Pro account

Get access to all 610 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
Meta Box Related Project’s Featured Image URL on Single Reviews

Meta Box Related Project’s Featured Image URL on Single Reviews

Updated on 26 Jun 2025 In a recent website I worked on, a requirement was to get the URL of the featured image of a…
Pro
ACPT Gallery Field Query Loop in Bricks

ACPT Gallery Field Query Loop in Bricks

How we can output images from ACPT‘s Gallery field for posts as a grid using a query loop.
Categories:
HappyFiles Bricks Query Loop

HappyFiles Bricks Query Loop

This tutorial explores different ways in which images from WordPress Media Library organized via HappyFiles can be pulled and shown in Bricks using query loop(s).…
Categories:
Pro
Update Post Meta From Another Custom Field’s Value on Post Publish/Update when using Meta Box

Update Post Meta From Another Custom Field’s Value on Post Publish/Update when using Meta Box

In the Meta Box Facebook group a user asks: Hi all, wondering if I can get some help. For custom field 1, I am using…
Categories:
Tags:
How to create filters with IsotopeJS in Bricks (Part 2): Dynamic Image Galleries

How to create filters with IsotopeJS in Bricks (Part 2): Dynamic Image Galleries

This tutorial series will review how to create a dynamic filterable image gallery using the IsotopeJS library‘s features in Bricks. Requirements Create a custom taxonomy for your…
Pro
Dynamic Source for Video Element in Bricks Using Meta Box Post Field

Dynamic Source for Video Element in Bricks Using Meta Box Post Field

This Pro tutorial provides the steps to set the source of a Bricks video element on single CPT pages to be the URL of a…
Categories: