WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Using p2p with get_posts (7 posts)

  1. Vyath
    Member
    Posted 2 years ago #

    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/

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    You should add:

    $countryargs = array(
    'suppress_filters' => false,
    ...
  3. Vyath
    Member
    Posted 2 years ago #

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

  4. scribu
    Member
    Plugin Author

    Posted 2 years ago #

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

  5. Vyath
    Member
    Posted 2 years ago #

    You're right!
    the problem was actually in "Custom Content Type Manager"

    Thank you for your help and sorry the inconvenience :)

  6. Eric Andrew Lewis
    Member
    Posted 2 years ago #

    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.

  7. scribu
    Member
    Plugin Author

    Posted 2 years ago #

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

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic