In a project that I am currently working on, there's a custom field group created in Advanced Custom Fields called "Trend report meta" and it has 'Report PDF' and 'Report Category' custom fields. This group is set to appear in a Custom Post Type named 'Trend Report'.
'Report Category' is a Select field with these pre-set values:
1: 1H 2014
2: 2H 2014
3: 1H 2015
4: 2H 2015
5: 1H 2016
6: 2H 2016
The requirement is to display the trend reports organized by the various categories like this:
In this article I share the code for showing the above on a Page. The idea is to obtain all the unique values of a custom field (meta key) across all entries of a specific CPT and then loop through the array of the custom field's values.
But first, screenshots of the backend:
Custom field group overview:
Report PDF and Report Category fields, expanded:
Sample Trend Report CPT entry:
First I placed a function that returns an array of unique values of a meta key from all Posts of a supplied CPT in child theme's functions.php:
To view the full content, please sign up for the membership.
Already a member? Log in below or here.