Post ObjectFREEPRO

Docs Fields Post Object

#Inline Post Create/EditPRO

The Post Object field includes new settings allowing users to create and edit post on-the-fly from the post edit screen.

Field Group
Add New
Add New
Setting nameDescription
Allow Post CreationAllow the user to create post in a modal. Allowed post types are based on the “Filter by Post Type” setting.
Allow Post EditAllow the user to edit the post in a modal.

#Iframe Arguments

The iframe which handle the post creation and edit will use URL parameters, allowing developers to use them.

https://www.domain.com/wp-admin/post-new.php?post_type=post&acfe_relation_type=add&acfe_relation_field_cid=acf129&acfe_relation_field_key=field_63c7834ac15e2&acfe_relation_field_name=post_object&acfe_relation_post_id=270&acfe_relation_is_admin=1
/**
 * acfe_relation_type=add                      // action type (add/edit)
 * acfe_relation_field_key=field_63c7834ac15e2 // field key
 * acfe_relation_field_name=post_object        // field name
 * acfe_relation_post_id=270                   // original post id
 * acfe_relation_is_admin=1                    // original request from admin
 */

It is possible to retrieve these arguments using $_GET or the acf_maybe_get_GET() function. Usage example:

add_filter('acf/prepare_field/name=my_field', 'my_prepare_field');
function my_prepare_field($field){
    
    // hide the field if inside the relationship iframe
    // originated from the front-end
    if(acf_maybe_get_GET('acfe_relation_is_admin') === '0'){
        return false;
    }

    // return normally
    return $field;

}

#Video Showcase

#Save Custom ValueFREE

Field Group
Setting nameDescription
Allow & save custom valueAllow the user to create post by typing a custom value in the Post Object. The value entered will be used as Post Title
Post TypeThe new Post Type
Post StatusThe new Post Status

#Custom Value HooksFREE

#New Post Arguments

/**
 * acfe/fields/post_object/custom_save_args
 * 
 * @array        $args     New Post arguments
 * @string       $title    Post title
 * @bool/string  $post_id  Current Post ID
 * @array        $field    Field array
 */
filter('acfe/fields/post_object/custom_save_args',                         $args, $title, $post_id, $field);
filter('acfe/fields/post_object/custom_save_args/name=my_post_object',     $args, $title, $post_id, $field);
filter('acfe/fields/post_object/custom_save_args/key=field_60131c20e748f', $args, $title, $post_id, $field);
add_filter('acfe/fields/post_object/custom_save_args/name=my_post_object', 'my_acf_post_object_new_post_args', 10, 4);
function my_acf_post_object_new_post_args($args, $title, $post_id, $field){
    
    // add custom Post Content
    // see: https://developer.wordpress.org/reference/functions/wp_insert_post/
    $args['post_content'] = 'My post content';
    
    // stop post creation
    // return false;
    
    // Return
    return $args;

}

#After Post Creation Hook

/**
 * acfe/fields/post_object/custom_save
 * 
 * @bool         $new_post_id  Newly created Post ID
 * @string       $title        Post title
 * @bool/string  $post_id      Current Post ID
 * @array        $field        Field array
 */
action('acfe/fields/post_object/custom_save',                         $new_post_id, $title, $post_id, $field);
action('acfe/fields/post_object/custom_save/name=my_post_object',     $new_post_id, $title, $post_id, $field);
action('acfe/fields/post_object/custom_save/key=field_60131c20e748f', $new_post_id, $title, $post_id, $field);
add_action('acfe/fields/post_object/custom_save/name=my_post_object', 'my_acf_post_object_new_post_action', 10, 4);
function my_acf_post_object_new_post_action($new_post_id, $title, $post_id, $field){
     
    // do something...
    // wp_mail();

}