WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] User to user ? (6 posts)

  1. DreadLox
    Member
    Posted 7 months ago #

    Hello,

    Are user 2 user relation supported ?

    Regard.

    http://wordpress.org/plugins/posts-to-posts/

  2. tedinoz
    Member
    Posted 6 months ago #

    From the documentation: "With this plugin, it's also possible to create many-to-many relationships between posts and users."

    Please explain what you understand by "user 2 user relation".

    Ted

  3. landwire
    Member
    Posted 6 months ago #

    Just looking for an example for that too. That is what I mean by user 2 user:

    Posts 2 Posts: Version 1.1

    I’m pleased to announce that the Posts 2 Posts plugin now also supports posts-to-users connections. (It supports users-to-users connections as well, but there’s no UI for them).

    I do not need a UI just an example of how to make a connection, use metadata etc.
    Thanks,
    Sascha

  4. landwire
    Member
    Posted 6 months ago #

    Ok, sorry for asking before, but maybe it would be good to post this as an example in the Wiki?

    To set-up a connection type:

    p2p_register_connection_type( array(
            'name' => 'user_to_office',
            'from' => 'user',
            'to' => 'user',
    		'fields' => array( // this creates extra meta fields that can be added to a connection - use to distinguish between connections by meta
    					'role' => array(
    						'type' => 'text',
    					),
    		)
        ) );

    Then to make a connection:

    // Create connection
    $from = 1; // user ID
    $to = 2; // user ID
    p2p_type( 'user_to_office' )->connect( $from, $to, array(
        'role' => 'KING!'
    ) );

    To display information:

    $user = 1;
    		$user_query = new WP_User_Query( array(
    			'connected_type' => 'user_to_office',
    			'connected_items' => $user,
    			) );
    
    		// User Loop
    		if ( ! empty( $user_query->results ) ) {
    			foreach ( $user_query->results as $user ) {
    				echo '<p>' . $user->display_name . '</p>';
    				echo 'Role: ' . p2p_get_meta( $user->p2p_id, 'role', true );
    			}
    		} else {
    			echo 'No users found.';
    		}

    Hope that helps somebody. Remember no UI for user2user!

  5. tedinoz
    Member
    Posted 6 months ago #

    Thanks landwire, and for adding it to the wiki too.

    Would you give me an example of a situation where one might use a user-to-user connection?

    Ted

  6. landwire
    Member
    Posted 6 months ago #

    1. Friend Connections
    2. 'Following' connections
    3. role 'office' to role 'employee'
    4. role 'office' to role 'boss'

    Plenty really. Anything where you have user accounts and then have accounts for certain roles, then connect them together.
    Sascha

Reply

You must log in to post.

About this Plugin

About this Topic

Tags