• J M

    (@hiphopinenglish)


    Using the P2P plugin to great effect. Thanks for all the great work. I’m encountering an issue on my Discography template, where I’m trying to show all albums, their associated artist(s) and associated producer(s). However, my second foreach loop (concerning producers), is returning the error mentioned above.

    Here is the code I’m using:

    <?php
    $args = array (
    						'post_type' 		     => 'hhie_albums',
    );
    
    $query_albums = new WP_Query( $args );
    p2p_type( 'albums_to_producers' )->each_connected( $query_albums, array(), 'producers' );
    p2p_type( 'albums_to_artists' )->each_connected( $query_albums, array(), 'artists' );
    if ($query_albums->have_posts() ) {
    while ($query_albums->have_posts() ) { $query_albums->the_post();
    foreach ( $post->artists as $post ) : setup_postdata( $post );
        the_permalink();
    endforeach;
    wp_reset_postdata();
    foreach ($post->producers as $post) : setup_postdata( $post );
        the_permalink();
    endforeach;
    wp_reset_postdata();
    }
    wp_reset_postdata();
    } else {
        echo 'Massive fail';
    }
    ?>

    Note that if I remove the first foreach loop (artists), then the second (producers) works fine. Anyone encountered the same issue?

    https://wordpress.org/plugins/posts-to-posts/

  • The topic ‘Invalid argument supplied for foreach()’ is closed to new replies.