Skip to content

Instantly share code, notes, and snippets.

@wesrice
wesrice / random-repeater.php
Created February 27, 2012 16:02
Return a random row of data from an ACF repeater field
<?php
// Get the repeater field
$repeater = get_field( 'repeater_field_name' );
// Get a random rows. Change the second parameter in array_rand() to how many rows you want.
$random_rows = array_rand( $repeater, 2 );
// Loop through the random rows if more than one is returned
if( is_array( $random_rows ) ){
@wesrice
wesrice / gist:1551880
Created January 2, 2012 19:58
ACF Reciprocal Relationship Functionality
<?php
function update_value( $post_id, $field, $value ){
// Check to see if there are any old relationships
if( parent::get_value( $post_id, $field ) !== '' ){
// If so, find out what needs to be added or deleted
$old_value = explode( ',', parent::get_value( $post_id, $field ) );
$new_value = explode( ',', $value );