Skip to content

Instantly share code, notes, and snippets.

@wkw
Created October 3, 2014 21:17
Show Gist options
  • Select an option

  • Save wkw/141f8e39537afc5ed4a2 to your computer and use it in GitHub Desktop.

Select an option

Save wkw/141f8e39537afc5ed4a2 to your computer and use it in GitHub Desktop.
CFS Transfer Fields between Posts
/**
* Get CFS fields for a post.
* pass post_id in $_GET('id')
*
* invoke with: /wp-admin/admin-ajax.php?action=cfs_values&id=10
* include raw=1 to get the unencoded data: /wp-admin/admin-ajax.php?action=cfs_values&id=10&raw=1
*/
function ajax_get_cfs_post_values(){
$options = array('format' => 'raw');
$field_data = CFS()->get(false, intval($_GET['id']), $options);
if( isset($_GET['raw']) ){
print_r($field_data);
}else{
$safe_string_to_store = base64_encode(serialize( $field_data ));
echo $safe_string_to_store;
}
die();
//to unserialize...
//$array_restored_from_db = unserialize(base64_decode($data));
//$post_data = array('ID' => 5864);
//CFS()->save($array_restored_from_db, $post_data);
}
add_action( 'wp_ajax_cfs_values', 'ajax_get_cfs_post_values' );
add_action( 'wp_ajax_nopriv_cfs_values', 'ajax_get_cfs_post_values' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment