WordPress.org

Support

Support » Plugins and Hacks » Showing linked posts in loop

Showing linked posts in loop

  • Hello,
    This plugin seems like it’s extremely powerful, but I’m just trying to figure out how to output a list of linked posts within a loop of the parent. My relationship is setup between post types (one of “ideas” and one of “tasks”). I’m trying to add

    SubPosts::API()->get_childs( $link_id, $parent_id )

    within the loop of a single post page for the “ideas” post type, so it will show the attached sub posts dynamically depending on what post we are currently on. If everything was outputted in a list that’d be helpful too. I just need a full sample of the code (I’m assuming I can use $post->ID for $parent_ID but what is $link_ID for, and how do I echo out the results?)

    Any help is appreciated.
    Thank you!

    http://wordpress.org/extend/plugins/sub-posts/

Viewing 1 replies (of 1 total)
  • Plugin Author Barry Kooij
    Participant

    @barrykooij

    Hi there,

    The ‘get_childs’ function is indeed the function you’re looking for. It returns you regular WordPress posts objects, just like e.g. WP_Query.

    The $link_id is the ID of the link of the post type link. If your “ideas” to “tasks” link was the first you’ve created the ID will be 1. If you want to be sure what the ID is go to your Sub Posts edit screen in de admin panel and edit the specific link. While in the post type link edit screen check your url for “&id=”. The number behind the “=” mark will be the ID you’re looking for.

    Once you’ve found out the post type link ID you only need to use the ‘get_childs’ function. In your case this will probably be:

    $tasks = SubPosts::API()->get_childs( 1, $post->ID );

    Now you can simply loop through the $tasks array and output the tasks posts any way you like.

    I’ll be happy to help you out if you have any more questions.

    Kind Regards,
    Barry

Viewing 1 replies (of 1 total)
  • The topic ‘Showing linked posts in loop’ is closed to new replies.