WordPress.org

Ready to get started?Download WordPress

Forums

Posts 2 Posts
[resolved] Merging 2 connection arrays? (5 posts)

  1. Twansparant
    Member
    Posted 2 years ago #

    Hi scribu,

    I'm struggling with this domtab menu;

    I have 2 sets of connected posts, both of them have the same connection field called 'event-time'. What I would like to do is combine these 2 arrays into 1 and then split the posts according to the given value in the 'event-time' connection field into domtabs (yes I'm that guy that uses that 'p2p_split_posts' function)

    $c_projects = new WP_Query( array(
    	'connected_type' => 'event-project',
    	'connected_items' => get_queried_object_id()
    ) );
    $c_artists = new WP_Query( array(
    	'connected_type' => 'event-artist',
    	'connected_items' => get_queried_object_id()
    ) );
    $c_artists_projects = array_merge($c_projects, $c_artists);
    $buckets = p2p_split_posts($c_artists_projects, 'event-time' );

    The above code gives me an error saying: 'Argument #1 is not an array'

    Can this be done? Any help is welcome.
    Thanks again for your great work by the way, loving this plugin!

    Cheers

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

  2. scribu
    Member
    Plugin Author

    Posted 2 years ago #

    $c_artists_projects = array_merge(
        $c_projects->posts,
        $c_artists->posts
    );
  3. Twansparant
    Member
    Posted 2 years ago #

    You're brilliant! Thanks

  4. Twansparant
    Member
    Posted 2 years ago #

    Hi scribu,

    I have one more thing; after succesfully splitting the connected posts into domtab groups with p2p_split_posts, I want to display connected posts from a different connection type for the post_type 'project' only in the main loop.

    Here's my code: http://pastebin.com/9cfVuKxz

    Everything works great, however the loop in the connected posts that also have a 'artist-project' connection stops after displaying:
    <h4><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></h4>

    And the one that don't display correctly.
    I think it might have something to do with the $post variable or resetting the query somehow?

    Any thoughts? Thanks!

  5. Twansparant
    Member
    Posted 2 years ago #

    Never mind, seconds after posting I realised it was the $post variable...
    So I assigned a seperate variable to hold the original post id and used that one:
    <?php $projectid = $post->ID; ?>
    Thanks anyway!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic