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 612 Bricks code tutorials with BricksLabs Pro

Related Tutorials..

Pro
MB Favorite Posts in Bricks

MB Favorite Posts in Bricks

This tutorial explores using MB Favorite Posts in Bricks, including outputting the list of favorites via a query loop.
Categories:
Pro
Dynamic Accordion in WordPress using Meta Box and Alpine.js

Dynamic Accordion in WordPress using Meta Box and Alpine.js

This Pro tutorial provides the steps to implement an accordion using Alpine.js in WordPress that pulls the values of sub fields of a Meta Box…
Pro
Meta Box Group’s Number Sub Field Values Sum

Meta Box Group’s Number Sub Field Values Sum

In the Bricks Facebook group a user asked: We can define a custom function that takes a Meta Box group ID, the sub field ID…
Categories:
Tags:
Pro
HappyFiles Folder Images via Meta Box Taxonomy Field in Bricks Image Gallery

HappyFiles Folder Images via Meta Box Taxonomy Field in Bricks Image Gallery

How to set the source of Bricks’ Image Gallery element on a post to images in the selected HappyFiles Folder(s) via a Meta Box Taxonomy…
Pro
Dynamic HappyFiles Gallery in Bricks with Meta Box or ACF Pro

Dynamic HappyFiles Gallery in Bricks with Meta Box or ACF Pro

Updated on 12 Jul 2023 This Pro tutorial provides the steps to show the images uploaded to an "Image Advanced" type of custom field created…
Categories:
Pro
Meta Box Color Picker to CSS Custom Property Workflow in Bricks

Meta Box Color Picker to CSS Custom Property Workflow in Bricks

This Pro tutorial provides the steps to declare a custom property (CSS variable) whose value is equal to the post-specific color set via a custom…
Categories:
Tags:
Pro
Post Data for the Current User in Bricks with Meta Box

Post Data for the Current User in Bricks with Meta Box

How to configure a query loop to output the post data of the SalesRep CPT associated with the current user.
Categories:
Limiting the Query Loop Posts Output to Post IDs From a Custom Field in Bricks

Limiting the Query Loop Posts Output to Post IDs From a Custom Field in Bricks

A user asks: Recently Bricks introduced the PHP query editor that lets us modify the query parameters right within the query dialog of the builder…
Categories:
Tags: