[Plugin: Posts 2 Posts] Displaying Connection information in the Admin Dashboard
-
I have a Posts to Users connection named “checked_out.” I am working on a custom widget for my Admin Dashboard that will display the connection box information for all Posts with connections. I have mostly achieved this, but there is one issue that I can’t seem to straighten out.
Here is what happens.
Each post title (that has a connection) is displayed correctly, along with the connection field information – So far, so good. However, I also want it to show the Display Name of the User connected to that post. Instead of displaying that user, a list of all users with connections to any post is displayed, like so:Post Title1 | Copy #: 2 | Due Date: 8/1/2012
On loan to: Username1
On loan to: Username2
On loan to: Username3
On loan to: Username4Post Title2 | Copy #: 1 | Due Date: 7/29/2012
On loan to: Username1
On loan to: Username2
On loan to: Username3
On loan to: Username4My connection box is registered as:
p2p_register_connection_type( array( 'name' => 'checked_out', 'from' => 'user', 'to' => 'post', 'cardinality' => 'many-to-many', 'sortable' => 'any', 'admin_column' => 'any', 'to_query_vars' => array( 'role' => 'subscriber' ), 'title' => array( 'from' => '', 'to' => 'Checked Out To:' ), 'fields' => array( 'copy' => array( 'title' => 'Copy #', 'values' => array( '1', '2', '3', '4' ) ), 'check-out_date' => 'Check-Out Date', 'due_date' => 'Due Date', ) ));
The code within the dashboard widget is:
$posts = get_posts(array( 'numberposts' => -1, 'connected_type' => 'checked_out', 'connected_items' => $user, )); $users = get_users( array( 'connected_type' => 'checked_out', 'connected_items' => $post, )); if($posts) { echo '<ul>'; foreach($posts as $post) { echo '<p>'; echo '<li><a href="' . get_edit_post_link($post->ID) . '">' . get_the_title($post->ID) . '</a> | Copy #: ' . p2p_get_meta( $post->p2p_id, 'copy', true ) . '</li>'; echo '<li>Due Date: ' . p2p_get_meta( $post->p2p_id, 'due_date', true ) . '</li>'; foreach($users as $user) { $patron = $user->display_name; echo '<li><strong>On loan to: ' . $patron . '</strong></li>'; } echo '</p>'; } echo '</ul>'; }
The “foreach users” loop has to be what is calling all the users with connections, but I can’t figure out how to specify the right user.
Any suggestions would be appreciated. Thank you!
- The topic ‘[Plugin: Posts 2 Posts] Displaying Connection information in the Admin Dashboard’ is closed to new replies.