Created
August 24, 2017 04:21
-
-
Save phucdohong96/703ab3293d933ead59aa82023456703c to your computer and use it in GitHub Desktop.
Shortcode Sample ACF Post Object & ACF Repeater
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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(); | |
} | |
} |
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
shortcode_post_object.php helped me!
Thanks!