Get ACF Repeater field value

So you’re using ACF‘s repeater field to store your data and are wondering if there’s an easier way to get its value? Here’s how:

/**
 * Get ACF repeater field value
 *
 * @param int|object $post          Post ID/object
 * @param string     $meta_key      Meta key
 * @param array      $subfield_keys Subfield keys
 *
 * return mixed
 */
function kucrut_get_acf_repeater_field_value( $post, $meta_key, Array $subfield_keys ) {
    $post = get_post( $post );
    if ( ! ( $post instanceof WP_Post ) ) {
        return false;
    }

    $count = absint( get_post_meta( $post->ID, $meta_key, true ) );
    if ( empty( $count ) ) {
        return false;
    }

    $values = array();
    for ( $i = 0; $i < $count; $i++ ) {
        $item = array();
        foreach ( $subfield_keys as $sub_key ) {
            $item[ $sub_key ] = get_post_meta(
                $post->ID,
                sprintf( '%s_%d_%s', $meta_key, $i, $sub_key ),
                true
            );
        }
        $values[] = $item;
    }

    return $values;
}

Custom byline markup for Co-Authors Plus

Co-Authors Plus is a nice plugin for assigning multiple authors to posts. However, I find its template tag for displaying byline rather limiting because sometimes we want to use fancy markup for the byline (think of avatars, publish/modification dates, etc). You can use the code below as the base for your theme’s byline markup (in this example, we’re overriding twentyfourteen_posted_on()):
Continue reading →