-
-
Save dexit/9a12e97047a5f2cb61406b97bd245ed7 to your computer and use it in GitHub Desktop.
Shortcode Sample ACF Post Object & ACF Repeater
This file contains hidden or 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 hidden or 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(); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment