Skip to content

Instantly share code, notes, and snippets.

@phucdohong96
Created August 24, 2017 04:21
Show Gist options
  • Save phucdohong96/703ab3293d933ead59aa82023456703c to your computer and use it in GitHub Desktop.
Save phucdohong96/703ab3293d933ead59aa82023456703c 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();
}
}
@BryanBarrera
Copy link

shortcode_post_object.php helped me!

Thanks!

@dexit
Copy link

dexit commented Dec 1, 2020

shortcode_post_object.php helped me too!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment