Ok, so the idea is that you have an outer loop, that displays the tours.
And then you have an inner loop, that displays each artist.
The way The Loop works is that it populates a lot of global variables, such as $post, so it looks like magic.
Let’s look at a more uniform approach:
$tours = get_posts( array(
'post_type' => 'tours',
'nopaging' => true,
'each_connected_to' => array(
'post_type' => 'artists',
'nopaging' => true,
),
'suppress_filters' => false
) );
// outer loop
foreach ( $tours as $tour ) {
echo get_the_title( $tour->ID );
echo get_post_meta( $tour->ID, 'ticket_link', true );
// inner loop
foreach ( $tour->connected_to as $artist ) {
echo get_the_title( $artist->ID );
echo '<br/>';
}
}
Update: This answer is obsolete; for a current example, see https://github.com/scribu/wp-posts-to-posts/wiki/Looping-The-Loop
Related Posts:
- Enable comments for post with comments meta box removed
- Custom Post Type causes Page Not Found
- [Plugin: Posts 2 Posts] How does it work?
- Is there a way to order posts and custom post types as one group?
- Accessing post’s meta data based on user’s click of a post
- get_post_type on post.php
- Matching Chapters to a Custom posts [closed]
- Redirect to another page using contact form 7? [closed]
- How to delete all trashed item in one-go
- Custom setup of wordpress comments that are displayed
- posts from multiple post types in one slider
- Show related posts based of current ACF field name in a single page post (a loop within loop)
- Custom Template for wordpress cpt plugin
- What hook can I use to modify custom post data before it is displayed on the page?
- Is it possible to pin a post in second position from top
- Is there a hook similar to “save_post” which only fires AFTER the post is completely published?
- Adding custom post category to categories widget
- How to display the custom post related blog by category?
- WordPress hide post from custom post-type on a single page
- Is it possible to customize a wordpress post from outside dashboard(Something like site.com/post-type/post/?e=post_id)?
- WordPress list child pages of custom post type
- Insert data in custom table during new post creation
- How to export post tags from wordpress
- How to check if the post exists in any of the categories?
- Is it possible to define a template for a custom post type within a plugin independent of the active theme?
- Show Similar Post Titles ( Similar to Stack Exchange )
- Delete Post With No Traffic?
- Automatically Creating Posts for Popular Forum Topics or Products [closed]
- Let readers suggest edits from the frontend
- Auto-post to multiple sites like Posterous? [closed]
- Article source link for posts
- Register Custom Post Type from Plugin
- Updating post meta for custom post types
- Template for custom post type shows all posts instead of just one
- Is there a plugin to display certain posts on certain pages? [closed]
- Frontend editing, Frontend user dashboard
- Override plugin with functions.php
- Get the url of the full sized attachment image using post ID?
- Adding Attachment Display Settings in custom media frame
- Should i delete the posts created by a plugin on uninstall?
- Output HTML only on individual post view
- How does WP handle multiple matching rewrite rules?
- Is it possible to use WordPress as an online portfolio for text content? What kind of theme would I look for?
- Portfolio + Blog: multisite or plugin?
- Building a store locator with google maps
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- One-to-many post relationships that are displayed by category (using posts-to-posts plugin)
- Correct way to make meta box with more than one meta field secure
- I want to extend the current themes’ single.php to display the meta fields of my CPT
- How can I create a custom shortcode that will return a custom post type by ID?
- How to enable qTranslate languages tabs in custom plugin page
- more types plugin – display all post of post type on page
- Making a Template for a CPT created by a plugin
- auto populate list of questions if user select a category xyz
- posts comments goes to trash
- Unable to delete custom post types, confusion around capabilities
- How can I use a file in my plugin as a replacement for single.php on custom-post-type query?
- Edit Permalink Structure For Custom Post Type or Modify .htaccess?
- Don’t publish/update a post when a plugin finds errors in custom fields
- How to set category correctly for a custom post created by a remote API call?
- Moving FB comments at the end of page
- Creating an admin meta box to save post as pending
- I would like to remove date display on photo preview
- Change website directory safely to add a static page on startup
- Price comparison table based on Custom Post Type?
- Get data from wp_posts of mysql in to variables of wordpress-php script
- WordPress “Add new tag” button is not working
- “After file loaded” action
- Problem with ajax plugin for refreshing posts
- Add posts from other WordPress blog to the current one
- Link Posts to External URL
- How do I allow users to supply a photo/image to be used instead of the grey/white silhouette?
- How to create repeater field manually, without plugin (ACF Pro)?
- how to create hierachial taxonomy and manage under single post type?
- Check if theme supports sidebar
- Custom Post Type same name as Category
- WP Forms not displaying,becomming an fatal error
- Undefined index: custom_post_template_present
- $wpdb->insert not working inside save_post tag
- Pagination (including title of each page) in a post for a long posts
- Include post_date in search
- Add Filter to get_next_posts_link
- Trending Tags based on post views
- Array to string conversion error when trying to POST multidimensional array
- WordPress custom posttype meta values doesnot save
- Assigning a custom post type to a custom page
- making a glossary with wordpress
- Create custom fields on a post
- Find And Add Category to Posts
- Retrieve post thumbnails
- get_option include in my adsense
- featured image problem with custom post type
- How can I default a new post to being saved?
- Automatically set posts to NoIndex depending on category?
- Change the behaviour of archive cpt category and single cpt by plugin, not by theme
- A plugin for software reviews site like this one?
- Display Custom Post Type and Custom Taxonomy Data on Front End Using Only a Plugin
- Links not opening as they should. Custom WP plugin
- How do I know if an archive correspond to a custom post type taxonomy?
- How to show custom post type in all post section?