Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save BryanBarrera/bc50da5ceda888a96d791ed4d7538a0d to your computer and use it in GitHub Desktop.
Save BryanBarrera/bc50da5ceda888a96d791ed4d7538a0d to your computer and use it in GitHub Desktop.
Shortcode Sample ACF Post Object & ACF Repeater
<?php
function shortcode_post_object_function() {
ob_start();
$count = 0;
//Get field
$post_objects = get_field ('post_objects');
if (!empty($post_objects)) {
foreach ($post_objects as $post_object) {
$id = $post_object->ID;
$title = $post_object->post_title;
$image = get_the_post_thumbnail($id,'large');
$excerpt = $post_object->post_excerpt;
$link = get_permalink ($id);
$content = $post_object->post_content;
?>
<!-- HTML Content -->
<?php
$count++;
}
wp_reset_postdata();
return ob_get_clean();
}
}
<?php
function shortcode_repeater_function() {
ob_start();
$count = 0;
//Get field
$repeaters = get_field ('repeaters');
if (!empty($repeaters)) {
foreach ($repeaters as $repeater) {
$sub_field1 = $repeater['sub_field1'];
$sub_field2 = $repeater['sub_field2'];
?>
<!-- HTML Content -->
<?php
$count++;
}
wp_reset_postdata();
return ob_get_clean();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment