Support

Account

Home Forums Add-ons Flexible Content Field AJAX update_sub_field on user profile

Unread

AJAX update_sub_field on user profile

  • I am trying to update a True/False box using update_sub_field. I can’t get any of the content to update, not even a wysiwyg box. I have used different combinations of field keys and names but the documentation doesn’t outline which parts are needed to reference the correct field. I am using a function in functions.php called by an ajax call. The function is running as it is returning the user_id.

    function acf_update_user_notification() {
    
    	if ( isset($_POST['user-id']) && isset($_POST['note-id']) ) {
    		$currNote = $_POST['note-id']-1;
    		echo 'user_' . $_POST['user-id'];
    		update_sub_field(
    			array(
    				'field_5c76a4e6b4e7d', $currNote,
    				'field_5c76ad9bb4e7f'
    			), 'Test Content', 'user_' . $_POST['user-id']);
    	}
    	exit();
    }
    
    add_action('wp_ajax_updateNote', 'acf_update_user_notification');

    AJAX call

    <script type="text/javascript">
    	function notificationRead(note_id) {
    		jQuery.ajax({
    			url: ajaxurl,
    			method: 'POST',
    			data: {
    				'action': 'updateNote',
    				'user-id': '<?php echo $user_id;?>',
    				'note-id': note_id
    			},
    			success: function(successData){
    				console.log('Success!');
    				console.log(successData);
    			},
    			error: function(errorData){
    				console.log('Error!');
    				console.log(errorData);
    			}
    		});
    	}
    </script>

    Image of flexible content settings
    User Notification ACF Settings

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.

We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Cookie Policy. If you continue to use this site, you consent to our use of cookies.