Title: [Plugin: Posts 2 Posts] Connection Ordering
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Connection Ordering

 *  Resolved [jdunneirl](https://wordpress.org/support/users/jdunneirl/)
 * (@jdunneirl)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/)
 * Hi ya,
 * I having lots of trouble with connection ordering
 * To register the connection I use
 *     ```
       global $carousel_connection;
       $carousel_connection =	p2p_register_connection_type( array(
       			'to' => 'carouselcontent',
       			'from' => 'carousel',
       			'title' =>  array('to'=> 'Content','from'=> 'Carousel'),
       			'sortable' => '_order'
       		) );
   
       add_action( 'init', 'carousel_connection', 100 );
       ```
   
 * Then on display I use
    `$carouselContent = new WP_Query( array( 'post_type' =
   > 'carouselcontent', 'post_per_page' => -1,'connected' => $carouselToUse,'connected_orderby'
   => '_order', 'order' => 'DESC'));`
 * Should this not work? I can drag and drop in the admin but the front end display
   ignores the order 🙁
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

Viewing 15 replies - 1 through 15 (of 15 total)

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366077)
 * No, it won’t work. You should use get_connected() instead:
 * [https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage](https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage)
 *  Thread Starter [jdunneirl](https://wordpress.org/support/users/jdunneirl/)
 * (@jdunneirl)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366137)
 * Thanks Scribu,
 * Still having problems though
 * how do I convert the wp_query to get_connected()
 *     ```
       $carouselContent = new WP_Query(  array( 'post_type' => 'carouselcontent', 'post_per_page' => -1,'connected' => $carouselToUse,'connected_orderby' => '_order', 'order' => 'DESC'));
   
       				$carouselContent = $carousel_connection->get_connected(array('connected' => $carouselToUse));
       ```
   
 * I am using 0.9 of the plugin,
 * Also this is not within the loop as I need to pass the post ID I am referncing
 * John
 *  Thread Starter [jdunneirl](https://wordpress.org/support/users/jdunneirl/)
 * (@jdunneirl)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366138)
 * Oh just to follow up
 * when I use
 * `$carouselContent = p2p_type( 'posts_pages' )->get_connected( get_queried_object_id());`
 *     ```
       p2p_register_connection_type( array(
       			'id' => 'posts_pages',
       			'to' => 'carouselcontent',
       			'from' => 'carousel',
       			'title' =>  array('to'=> 'Content','from'=> 'Carousel'),
       			'sortable' => '_order'
       		) );
       ```
   
 * I get
 * Fatal error: Call to undefined function p2p_type()
 * If I use
 * `$carouselContent = $carousel_connection->get_connected(array('connected' => 
   $carouselToUse));`
 * I also error
 * Warning: Invalid post type. Expected ‘carousel’ or ‘carouselcontent’, but received”
 *  Thread Starter [jdunneirl](https://wordpress.org/support/users/jdunneirl/)
 * (@jdunneirl)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366139)
 * I sorted it turns out I was sending in a blank 🙁
 * thanks for all your help scribu, just one question how can you use posts2posts
   with wpquery I am not completely understanding the get_connected is this the 
   replacement for wp_query and does it take all the same args?
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366140)
 * get_connected() takes a post as the first argument:
 *     ```
       $carousel_connection->get_connected( $carouselToUse );
       ```
   
 * and _optionally_ any other WP_Query vars as the second argument:
 *     ```
       $carousel_connection->get_connected( $carouselToUse, array(
         'posts_per_page' => 10,
         '
       ) );
       ```
   
 * Note that you _don’t_ have to specify the post type or any other P2P specific
   arg.
 * Also, you should update to P2P 0.9.5 as older versions are not supported.
 *  [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * (@nicholas27)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366206)
 * Hi,
 * I love this plugin! And the drag and drop ordering is great! However, I am having
   a similar problem since the update, and I am a little confused on how to correctly
   do this now.
 * Right now I have, to connect 2 custom post types. ie. Songs to Albums:
 *     ```
       // Find connected songs
       $connected = new WP_Query( array(
       'post_type' => 'song',
       'nopaging' => false,
       'posts_per_page' => 30,
       'connected_orderby' => 'order',
       'connected_from' => get_queried_object_id()
       ) );
       ```
   
 * The sorting works on the admin side. But now the order seems to be random on 
   the front end and does not follow a discernible order.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366207)
 * [@nicholas](https://wordpress.org/support/users/nicholas/): I already described
   what you need to do in my previous replies.
 *  [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * (@nicholas27)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366209)
 * Hi scribu,
    I have been going through this post, as well as your GitHub page,
   but as mentioned, I am confused by the changes. I am not sure what to use and
   what to change. When I follow the process outlined in your Basic Usage example,
   I get an error. With the example above I am also not sure what $carouselToUse
   is… You say it is a post, but what is it being used for? My example does not 
   make use of a variable in that way, I only have the array. Do I not need any 
   of that anymore?
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366211)
 * > When I follow the process outlined in your Basic Usage example, I get an error.
 * What error? Are you using version 0.9.5?
 *  [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * (@nicholas27)
 * [14 years, 7 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366212)
 * I am using 0.9.5. I decided to start from scratch again and it is now working
   and ordering correctly!
 * Thank you very much scribu! Great plugin!
 *  [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * (@nicholas27)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366376)
 * Hi,
 * I am not sure what I have done wrong. When I last posted, my ordering was working.
   Now I check again, after changing nothing in my code and the ordering is wrong
   again.
 * Below is the code from my functions.php file:
 *     ```
       // Activating Post to Page relationship via Posts2Posts plugin. Source: https://github.com/scribu/wp-posts-to-posts/wiki/Basic-usage */
       function ncp_lr_connection_types(){
       	if ( !function_exists( 'p2p_register_connection_type' ) )
       		return;
   
       	p2p_register_connection_type( array(
       		'id' => 'posts_pages',
       		'from' => 'album',
       		'to' => 'song',
       		'sortable' => 'order'
       	) );
       }
   
       add_action('init','ncp_lr_connection_types', 100);
       ```
   
 * Here is my code in my page, used to display the connections:
 *     ```
       <?php
       $connected = p2p_type( 'posts_pages' )->get_connected( get_queried_object_id() );
       											// Display connected pages																					echo '<ul>';
       																						while ( $connected->have_posts() ) : $connected->the_post();
       $more = 0;?>
       													<li id="song-<?php the_ID();?>">
       etc...
       ```
   
 * I must be missing something here. As far as I can tell, the above code is correct.
   Or not?
 * Any help would be greatly appreciated.
 * Thank you.
 * Note: Using WP 3.2.1 and v 0.9.5 of plugin. Also using WP E-commerce and Gravity
   Forms on the site.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366377)
 * If you haven’t changed the code related to P2P it means something else changed.
   Perhaps some other plugin is conflicting with it.
 *  [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * (@nicholas27)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366378)
 * So my code above is correct?
 * Also, any known plugin conflicts?
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366379)
 * Yes, the code is correct.
 * No known plugin conflicts.
 *  [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * (@nicholas27)
 * [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366380)
 * Thank you for the rapid responses! Much appreciated!

Viewing 15 replies - 1 through 15 (of 15 total)

The topic ‘[Plugin: Posts 2 Posts] Connection Ordering’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/posts-to-posts_7a8e9d.svg)
 * [Posts 2 Posts](https://wordpress.org/plugins/posts-to-posts/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/posts-to-posts/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/posts-to-posts/)
 * [Active Topics](https://wordpress.org/support/plugin/posts-to-posts/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/posts-to-posts/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/posts-to-posts/reviews/)

 * 15 replies
 * 3 participants
 * Last reply from: [Nicholas](https://wordpress.org/support/users/nicholas27/)
 * Last activity: [14 years, 6 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-connection-ordering/#post-2366380)
 * Status: resolved