helpers.php
Helper functions for ACF field rendering and formatting
Tags
Table of Contents
Functions
- jpkcom_render_acf_fields() : void
- Renders all ACF fields of a post with Bootstrap 5 markup and smart icons
- acf_get_field_label() : string
- Get ACF field label by field key or field name
- jpkcom_get_acf_field_label() : string
- Get ACF field label with enhanced search capabilities
- jpkcom_human_readable_relative_date() : string
- Convert timestamp to human-readable relative date string
Functions
jpkcom_render_acf_fields()
Renders all ACF fields of a post with Bootstrap 5 markup and smart icons
jpkcom_render_acf_fields([string $post_type = '' ]) : void
Automatically detects field types and renders them with appropriate styling:
- Images: Responsive with rounded corners
- WYSIWYG/Textarea: Light background container
- Relationships/Post Objects: Linked post titles
- True/False: Badge indicators
- Repeater: Responsive tables
- Groups: Nested definition lists
Parameters
- $post_type : string = ''
-
Optional. Post type for field group query. Default empty (uses current post type).
Tags
acf_get_field_label()
Get ACF field label by field key or field name
acf_get_field_label(string $field_key_or_name) : string
Attempts to retrieve the field label from ACF. If not found, returns a formatted fallback based on the field name/key.
Parameters
- $field_key_or_name : string
-
Field key (e.g., 'field_abc123') or field name (e.g., 'job_title').
Tags
Return values
string —Field label or formatted fallback string.
jpkcom_get_acf_field_label()
Get ACF field label with enhanced search capabilities
jpkcom_get_acf_field_label(string $field_name_or_key[, string $post_type = '' ]) : string
Searches for field labels in this order:
- Direct field key lookup (if starts with 'field_')
- Search through field groups by post type
- Search through sub_fields (repeater/group fields)
- Fallback to formatted field name
Parameters
- $field_name_or_key : string
-
Field name (e.g., 'job_title') or field key (e.g., 'field_abc123').
- $post_type : string = ''
-
Optional. Post type for context-specific field group search. Default empty.
Tags
Return values
string —Field label or formatted fallback string.
jpkcom_human_readable_relative_date()
Convert timestamp to human-readable relative date string
jpkcom_human_readable_relative_date(int $timestamp) : string
Converts Unix timestamps into relative date strings like:
- "Published today"
- "Published yesterday"
- "Published 3 days ago"
- "Published 2 weeks ago"
- "Published 5 months ago"
- "Published 2 years ago"
All strings are translatable via the 'jpkcom-acf-references' text domain.
Parameters
- $timestamp : int
-
Unix timestamp to convert.
Tags
Return values
string —Translated relative date string.