function create_full_category_grid_shortcode() { // --- CONFIGURATION --- $taxonomy_slug = 'research-category'; $acf_field_name = 'research_category_featured_image'; // --- END CONFIGURATION --- $parent_terms = get_terms(array( 'taxonomy' => $taxonomy_slug, 'parent' => 0, 'hide_empty' => false, )); if (empty($parent_terms) || is_wp_error($parent_terms)) { return '

No parent categories found.

'; } $full_output = ''; foreach ($parent_terms as $parent_term) { $full_output .= '
'; $full_output .= '

' . esc_html($parent_term->name) . '

'; $child_terms = get_terms(array( 'taxonomy' => $taxonomy_slug, 'parent' => $parent_term->term_id, 'hide_empty' => false, )); if (!empty($child_terms) && !is_wp_error($child_terms)) { $full_output .= '
'; foreach ($child_terms as $child_term) { $term_link = get_term_link($child_term); $term_name = $child_term->name; $image_url = ''; $image_field = get_field($acf_field_name, $child_term); if ($image_field) { if (is_array($image_field)) { $image_url = $image_field['url']; } elseif (is_numeric($image_field)) { $image_url = wp_get_attachment_image_url($image_field, 'large'); } else { $image_url = $image_field; } } $full_output .= ''; if ($image_url) { $full_output .= '' . esc_attr($term_name) . ''; } $full_output .= '
'; $full_output .= '

' . esc_html($term_name) . '

'; $full_output .= '
'; $full_output .= '
'; } $full_output .= '
'; } $full_output .= '
'; } return $full_output; } add_shortcode('full_category_grid', 'create_full_category_grid_shortcode');