Support » Plugin: Posts 2 Posts » [Plugin: Posts 2 Posts] Using p2p with get_posts

  • Resolved Vyath


    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’,
    ‘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?

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Author scribu


    You should add:

    $countryargs = array(
    'suppress_filters' => false,

    Thank you for the fast reply!

    this is really strange –
    if I add ‘suppress_filters’ => false
    then it works


    ‘orderby’ => ‘title’
    refuses to work, meaning the posts are ordered only by date…

    Plugin Author scribu


    Try deactivating all other plugins, to make sure it’s a problem with P2P.

    You’re right!
    the problem was actually in “Custom Content Type Manager”

    Thank you for your help and sorry the inconvenience 🙂

    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


    '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.