Home Forums Backend Issues (wp-admin) Limit post object to author inside user-edit.php (backend user profile) Reply To: Limit post object to author inside user-edit.php (backend user profile)

  • Hi John,

    thank you for your help. I decided I ask on since it was a rather complex thing and Reigel Garllade came up with a good solution.


    I’ll share it here, in case anybody will ever run into the same issue. For me the issue is solved, but I am curious if you have objections to the following code.

    The following code goes into the functions.php

    function admin_footer(){
    	/* <![CDATA[ */
    	acf.add_filter('select2_args',function( args ) {
    			if ( typeof == 'function' ) {
    				var old_data_func =; // We'll keep this for maximum compatibility, and extend it.
    = function(term, page) {
    					var default_response = old_data_func( term, page ); // Call the old, default function.
    					// Add the user_id to the ajax function.
    					default_response.user_id = function () {return <?php echo isset($_GET['user_id'])?$_GET['user_id']:''; ?>;};
    					// Return the default args with our user_id function.
    					return default_response;
    			return args;
    	/* ]]> */

    and then:

    add_filter('acf/fields/post_object/query/name=featured_product', 'my_post_object_query', 10, 3);
    function my_post_object_query( $args, $field, $post ) {
    	// modify the order
    	if( isset($_POST['user_id']) && is_numeric($_POST['user_id'])) {
    		$user_id = $_POST['user_id'];
    	} else {
    		$current_user = wp_get_current_user();
    		$user_id = $current_user->ID;
    	return $args;