Skip to content

Instantly share code, notes, and snippets.

@dexit
Forked from phucdohong96/shortcode_post_object.php
Created December 1, 2020 11:55
Show Gist options
  • Select an option

  • Save dexit/9a12e97047a5f2cb61406b97bd245ed7 to your computer and use it in GitHub Desktop.

Select an option

Save dexit/9a12e97047a5f2cb61406b97bd245ed7 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