Bidirectional fields: CPT and Users – update on User import
-
Hi there,
Bidirectional fields are working great when:
- Adding a User to the Company Post Type
- Adding a Company to the User
This doesn’t update when importing Users with a Company ID attached.
- When Users are imported, the Company is correctly added
- The User is not shown though on the Company Post Type’s Users field
I have tried adding the following to functions (the first can be ignored)
add_action('admin_init', 'my_acf_update_bidirectional_posts'); function my_acf_update_bidirectional_posts(){ // bail early if ajax request if(wp_doing_ajax()){ return; } // Retrieve all pages $get_posts = get_posts(array( 'post_type' => 'r4l_companies', 'posts_per_page' => -1, 'fields' => 'ids', )); // Bail early if not found if(empty($get_posts)){ return; } // Force bidirectional update add_filter('acfe/bidirectional/force_update', '__return_true'); // Loop foreach($get_posts as $post_id){ // Retrieve unformatted value $my_field = get_field('field_6185189802029', $post_id, false); // Re-update the same value to force the update on the other side update_field('field_6185189802029', $my_field, $post_id); } }
and:
add_action('admin_init', 'my_acf_update_bidirectional_posts'); function my_acf_update_bidirectional_posts(){ // bail early if ajax request if(wp_doing_ajax()){ return; } // Retrieve all users $get_users = get_users(array( 'number' => '-1', )); // Bail early if not found if(empty($get_users)){ return; } // Force bidirectional update add_filter('acfe/bidirectional/force_update', '__return_true'); // Loop foreach($get_users as $user_id){ // Retrieve unformatted value $my_field = get_field('field_6185189802029', 'user_'. $user_id, false); // Re-update the same value to force the update on the other side update_field('field_6185189802029', $my_field, $user_id); } }
(I have used both the field names and keys).
Would it be possible to help with this? ??
Thanks very much for your help,
Robbi
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘Bidirectional fields: CPT and Users – update on User import’ is closed to new replies.