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
- 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
- Disallow a user to post in certain categories
- 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?
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- 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
- more types plugin – display all post of post type on page
- How to hide some section in WordPress under Post
- auto populate list of questions if user select a category xyz
- “Custom Post Type Permalinks” plugin URL strcuture
- Add category selection to custom post type (plugin)
- Custom Post Type Fields
- publish_post action doesn’t work
- Disable Individual Plugins (specifically in Custom Post Types) on a per-post basis?
- custom post type don’t appear in the home page
- Import Instagram post to WordPress blog post
- wordpress content .php file in an iframe’s src in a wordpress post
- Making my plugin create a page?
- How can I automatically download all images from all imported posts, place them on my new host, and replace all the links
- How do we update a custom file upload field with the Advanced Custom Field plugin?
- Function added to hook “new_to_publish” not executing – custom plugin
- Creating an admin meta box to save post as pending
- Preview with Custom Post Type Not Working
- If post exists in the database – each time goes on `else`
- Edit part of a post
- Rename existing cpt and taxonomy with new textdomain
- Best method of implementing compartmentalized custom post types on a multi-site network
- Can i stream data to a custom_post_type?
- Randomize post (and page) IDs on generation
- Moving all wordpress posts from 50 websites to another website
- save_post hook partly firing in update post
- Show post object of any page in frontend
- Trying to add a new feature in my wordpress website
- automatically set random featured image by category in wordpress on post
- Page not found after creating the add new post slider using custom post type
- Prefix WordPress Taxonomy Tags With Hashtag Symbol Like Twitter
- Failed to load resource: the server responded with a status of 500 () post.php
- How can I get the Post ID and Post Type within a Must Use Plugin?
- WordPress Dashboard organize posts based on categories
- Add new post using a page inside the website
- Related posts popup
- Find And Add Category to Posts
- WordPress ultra slow if I click on posts?
- Get page type to display content
- Capturing POST data
- Top Contributors Plugin with Custom Post Type
- featured image problem with custom post type
- Most visited posts
- Get a submitted value from front end post form for single template
- Automatically set posts to NoIndex depending on category?
- wp_update_post does not change post status from draft to publish, returns 1
- Is an Office a custom post type [closed]
- Notification When Post Approved
- How to hide home title on pages and posts?
- Snippet displaying LearnDash parent course title with lesson title [closed]
- Windows 10 Printer that Sends to WordPress [closed]
- My Blog page ( posts page ) theme isn’t changing with the new theme [closed]
- Links not opening as they should. Custom WP plugin
- Getting 400 Error in wordpress website
- How to provide page_template path in custom plugin using WordPress