WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] [Plugin: Posts 2 Posts] Edits args for get_connected() (3 posts)

  1. duck__boy
    Member
    Posted 2 years ago #

    I'm using the Posts 2 Posts plugin, which seems perfect for most of what I want to do, but there are a couple of features that I cannot work out through reading the documentation, so I wonder if someone could help?

    Firstly, I need to show connections in the 'to' direction in one instance -

    $children = p2p_type('service_parents_and_children')->set_direction('to')->get_connected(get_queried_object_id());

    This works, but with the default WP args being passed (5 posts, date order, etc) - is there a way to pass my own custom args so that I can get the posts displaying as I require?

    Also, I'm looking for a way of showing a posts 'siblings', I.e posts that have the same 'from' connection to a certain post (I have the ID of the post). I've explored get_related(), but I can't seem to get it to do what I want.

    This is a great plugin, so I'm fairly confident that these tasks can be acheived, so any help is greatly appriciated.

    Thanks

  2. scribu
    Member
    Posted 1 year ago #

    I didn't notice this thread because it doesn't show up in the plugin forum.

    is there a way to pass my own custom args so that I can get the posts displaying as I require?

    Yes, there is:

    $children = p2p_type('service_parents_and_children')
      ->set_direction('to')
      ->get_connected( get_queried_object_id(), array( 'additional' => 'query_var' ) );

    Or, more readable:

    $children = new WP_Query( array(
      'connected_type' => 'service_parents_and_children',
      'connected_direction' => 'to',
      'connected_items' => get_queried_object_id(),
      'additional' => 'query_var'
    ) );

    As for get_related(), please open a new topic:

    http://wordpress.org/support/plugin/posts-to-posts

  3. duck__boy
    Member
    Posted 1 year ago #

    Many thanks for getting back to me, I'll give that a try shortly as I don't think I ever got working quite as I wanted.

    Thanks.

Topic Closed

This topic has been closed to new replies.

About this Topic