Title: [Plugin: Posts 2 Posts] Using p2p with get_posts
Last modified: August 20, 2016

---

# [Plugin: Posts 2 Posts] Using p2p with get_posts

 *  Resolved [Vyath](https://wordpress.org/support/users/vyath/)
 * (@vyath)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/)
 * The plugin works great with wp_query, but I’m unable to get it to work using 
   get_posts
 * My code is as follows:
 *  `$countryargs =array(
    ‘orderby’ => ‘title’, ‘order’ => ‘ASC’, ‘post_type’ =
   > ‘country’, ‘posts_per_page’=>-1, ‘each_connected’ => array( ‘post_type’ => ‘
   distributor’ ));
 *  $loop = get_posts( $countryargs);
    foreach ($loop as $post) : setup_postdata(
   $post); ` and then get connected posts with `foreach ( $post->connected as $distributor)`
 * but I get
 * >  Warning: Invalid argument supplied for foreach() in /…path…/template_wheretobuy.
   > php on line 67
 * on the line trying to get connected posts
 * What should I do?
 * [http://wordpress.org/extend/plugins/posts-to-posts/](http://wordpress.org/extend/plugins/posts-to-posts/)

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

 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303211)
 * You should add:
 *     ```
       $countryargs = array(
       'suppress_filters' => false,
       ...
       ```
   
 *  Thread Starter [Vyath](https://wordpress.org/support/users/vyath/)
 * (@vyath)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303227)
 * Thank you for the fast reply!
 * this is really strange –
    if I add ‘suppress_filters’ => false then it works
 * BUT
 * ‘orderby’ => ‘title’
    refuses to work, meaning the posts are ordered only by 
   date…
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303229)
 * Try deactivating all other plugins, to make sure it’s a problem with P2P.
 *  Thread Starter [Vyath](https://wordpress.org/support/users/vyath/)
 * (@vyath)
 * [14 years, 8 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303233)
 * You’re right!
    the problem was actually in “Custom Content Type Manager”
 * Thank you for your help and sorry the inconvenience 🙂
 *  [Eric Andrew Lewis](https://wordpress.org/support/users/ericlewis/)
 * (@ericlewis)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303493)
 * Thoughts on adding a suppress_filters => false by default to WP_Query so get_posts
   works out of box with the plugin? Not sure if possible but would be nice.
 *  Plugin Author [scribu](https://wordpress.org/support/users/scribu/)
 * (@scribu)
 * [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303494)
 * `'suppress_filters' => false` already is the default in WP_Query.
 * `get_posts()` defaults to `'suppress_filters' => true` for compatibility reasons(
   it didn’t use WP_Query initially).

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

The topic ‘[Plugin: Posts 2 Posts] Using p2p with get_posts’ 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/)

 * 6 replies
 * 3 participants
 * Last reply from: [scribu](https://wordpress.org/support/users/scribu/)
 * Last activity: [14 years, 2 months ago](https://wordpress.org/support/topic/plugin-posts-2-posts-using-p2p-with-get_posts/#post-2303494)
 * Status: resolved