Hooked to POST CREATION and STATUS CHANGE

 

We do use  wp_insert_post() and wp_update_post() for creating and updating the custom post.

We added the group access update upon every status change with these IDs:

$_POST[‘group_access’] = array(
178,
182,
186,
);

 

 

====

 

Without seeing your code how you actually create the draft post it’s a bit tricky.

iMember360 is hooked into the wp_insert_post hook and adds the permissions if they are given in a $_POST array. Theoretically, this hook callback should be triggered when you insert the post, but without the permission settings in your case. Therefore, assuming that you create the post through WordPress functions, we only need to set the $_POST[‘group_access’] array with the correct membership level tag IDs, and our hook callback for wp_insert_post will set the permissions.

If you’re using wp_insert_post() function for the post creation, it could look like this:

$_POST[‘group_access’] = array(
123, // Replace with the correct iMember360 tag IDs
456,
);

$post_data = array(
‘post_title’   => ‘My Draft Post’,
‘post_content’ => ‘This is the initial content.’,
‘post_status’  => ‘draft’,
‘post_author’  => get_current_user_id(), // Or a fixed user ID
‘post_type’    => ‘post’, // Or custom post type
);

// Insert the post into the database
$post_id = wp_insert_post( $post_data );

Let me know if that helps or if you need further assistance!

Best,
John

 

Please note that you need to apply the membership level tag IDs every time you save, not just during the initial creation when the post is set to draft. When you finalize the post with the member’s content and change its status to “publish,” you must apply the membership level tag IDs again (or at that point only). It is not strictly necessary when you first create the post as a draft, but on every subsequent save; otherwise, the content will become public.