• Resolved Lars Friberg

    (@larsfriberg)


    Hi

    I working on a site where we have a custom post type, event connected to user

    Here is the connection.

    p2p_register_connection_type(
    	[
    		'name'   => self::get_connection(),
    		'from'   => 'event',
    		'to'     => 'user',
    		'fields' => [
    			'going'     => [
    				'title' => __( 'Going', Plugin::get_text_domain() ),
    				'type'  => 'checkbox',
    				// 'default_cb' => [ $this, 'set_default' ],
    			],
    			'not_going' => [
    				'title' => __( 'Not Going', Plugin::get_text_domain() ),
    				'type'  => 'checkbox',
    			],
    		],
    	]
    );

    It has worked until we upgraded WordPress to 6.1 from 6.0.3. But now the checkboxes in backend is empty.

    Screenshot: https://lars.friberg.dk/p2p.png

    We add the data with some custom code in frontend, and it is saved in the database, but not shown in backend. I can add connections in backend, and the choice in backend is saved, but not shown.

    I can’t remove or changes connections in backend.

    • This topic was modified 1 year, 9 months ago by Lars Friberg.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Support alexrollin

    (@alexrollin)

    Hello,

    we aren’t able to reproduce this issue on our test sites.

    If you need further help please open a support ticket here :?https://wpgeodirectory.com/support/

    Hi Lars,

    Not sure if this will be usefull to you, hoping you found a solution since then, but this might be to others.. posts_2_posts connection management through meta boxes broke since wp 6.1 as they added a change in WP_User_Query (a not commented change) probably for performance purposes, ignoring the “all” value for query field list, and returning the full result only if there is an array of fields, else it returns user ID only.

    if ( is_array( $qv['fields'] ) ) {
    				$this->results = $wpdb->get_results( $this->request );
    			} else {
    				$this->results = $wpdb->get_col( $this->request );
    			}

    I tried by myself to modify posts_2_posts but i wasn’t sure how to, and didn’t have enough time to do so, bu t the fix is to pass an array of all user fields for any user query that is trying to use “all” in the $query->query_vars[‘fields’] value. or more specifically for your admin_box only..

    here is what i did to avoid a maximum of unknown consequences on wp code :

    add_action('pre_get_users',function($query){
    
    		if ( (isset( $query->query_vars['p2p:context'] ) && $query->query_vars['p2p:context'] == 'admin_box') 
    			&& (isset($query->query_vars['connected_direction']) && $query->query_vars['connected_direction'] == 'to') 
    			&& (isset($query->query_vars['connected_type']) && $query->query_vars['connected_type'] == 'my_p2p_connection_name')) {
    				$query->query_vars['fields'] = array(
    					'id',
    					'user_login',
    					'user_pass',
    					'user_nicename',
    					'user_email',
    					'user_url',
    					'user_registered',
    					'user_activation_key',
    					'user_status',
    					'display_name',
    				);
    			}
    			
    	});

    i tried to be very specific on the user_query i modify. but i guess you could just check on query_vars[‘fields’] == “all”.

    hope this will be usefull to someone or maybe a quick fix in posts_2_posts code if anyone can ? i must say i’d love to continue using it , as it’s the best plugin i know that handles connections like this !

    Thread Starter Lars Friberg

    (@larsfriberg)

    @cyberie

    I also find that the problem was from the change in WP_User_Query.

    I ended up to make my ovn meta box in this case.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Conneted users and WP 6.1’ is closed to new replies.