Sunday, 2 June 2013

Front end edit Post_content with ACF plugin

Front end edit Post_content with ACF plugin

I have this function that works with Advanced Custom fields plugin. What it does is allow me to change post_content with the custom field called "custom_post_content", and it also syncs what is currently in the post_content.
Here is the function
add_action('acf/save_post', 'change_content_frontend');
function change_content_frontend($post_id) {

if(get_post_type( $post_id ) != 'acf'){ //This function won't run if adding/updated fields/field-groups in wp-admin
    $post_content = get_post_meta($post_id,'custom_post_content',true);

    $my_post = array();
            $my_post['ID'] = $post_id;
            $my_post['post_content'] = $post_content;
remove_action('acf/save_post', 'change_content_frontend');
                wp_update_post( $my_post );
add_action('acf/save_post', 'change_content_frontend');

add_filter( 'acf/update_value/name=custom_post_content', 'acf_load_value_user_post_content', 10, 3 );
function acf_load_value_user_post_content( $value, $post_id, $field  )
{
$post    = get_post($post_id);
$value   = $post->post_content;
return $value;
}
}
}
What do I want to do?
My goal is the following: 1. In the post edit screen, I would like to use the normal WYSIWYG field to edit the post content. 2. on the font-end I would like to use the custom field to change the post content.
ACF has a nice front end form function that works well. How can I make this funtion work only in the front end?
Why ACF?
The reason for this is because using ACF front end form is an easier way for me to allow front end editing of post_content . If anyone has seen a tutorial way on a simpler way to edit post_content from the front end, i will also be appreciative.

No comments:

Post a Comment