Created
October 3, 2014 21:17
-
-
Save wkw/141f8e39537afc5ed4a2 to your computer and use it in GitHub Desktop.
CFS Transfer Fields between Posts
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
| /** | |
| * 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