Created
May 29, 2017 15:44
-
-
Save palicko/a64d806d4b24462dc004487f8f3342ec to your computer and use it in GitHub Desktop.
ACF repeater via get_post_meta()
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 | |
// Returns array with repeater subfields and its values | |
function repeater_get_post_meta( $repeater_key, $post_id, $sub_field_keys ) { | |
if ( ! $post_id ) { | |
$post_id = get_the_ID(); | |
} | |
// get repeater field | |
$repeater = get_post_meta( get_the_ID(), $repeater_key, true ); | |
$repeater_output = array(); | |
if( $repeater ) { | |
// loop through repeater fields | |
for( $i = 0; $i < $repeater; $i++ ) { | |
// loop through subfields | |
for( $j = 0; $j < $sub_field_keys; $j++ ) { | |
$repeater_output[$i][$sub_field_keys[$j]] = get_post_meta( get_the_ID(), $repeat_key . '_' . $i . '_' . $sub_field_keys[$j], true ); | |
} | |
} | |
} | |
return $repeater_output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment