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
- Disable All In One SEO plugin for custom post type
- How to check if the post exists in any of the categories?
- Bulk Image Uploader to create new post from each image [closed]
- How use %like% in sql statement wordpress
- Display comments of users on single page
- wordpress reusable content blocks
- Override plugin with functions.php
- Get the url of the full sized attachment image using post ID?
- Adding Plugin-specific Fields with wp_insert_post()?
- 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
- Allow users mark posts as “complete”?
- Using the “Latest posts” feature on a different site
- Post query – show posts from specified day and month and whole years
- Execute a plugin only on post pages
- RW Meta Box ,Problem setting post title
- How can i list random post from multiple category?
- How does WP handle multiple matching rewrite rules?
- Support for simultaneous editing
- how do i remove posts from a WP_Query so the pagination is right?
- Saving Custom Post types and fields to a custom table
- dynamically generating plugin syntax
- How to get 1 or 2 specific posts on top of my wordpress blog?
- 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
- Duplicate posts when posting nulls in records in phpMyAdmin [closed]
- How to make wp_enqueue_style and wp_enqueue_script work only on custom post type
- Loco Translate: Custom Post and Custom Taxonomy Labels not translated in wp-admin menu
- One-to-many post relationships that are displayed by category (using posts-to-posts plugin)
- View Private Published Page with URL Code (no login required)
- With W3 Total Cache when I publish a post it does not appear in the homepage. Only if i purge all cache [closed]
- If post has custom field then display css-class
- The problem with WordPress Importer
- How to create user groups and allow custom posts and plugin modify/access to specific group?
- 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
- Cron job not firing
- Plugin custom post type – Internal server Error
- Exclude post by custom meta with pre_get_posts
- Solutions to repost categories into multisite blogs?
- 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
- How do I “get the next 10 posts after post_id == x”?
- Hiding posts – WP Hide Post not working
- Is it possible to create Custom Post plug-in?
- get_post_type() and WP_QUERY issue
- submit posts by unregistered users in wordpress
- Calendar Solution: Handling upcoming Dates with Posts?
- Is there an easy way to flag posts in the admin area?
- List taxonomy terms for post as checkboxes
- All of my custom posttypes are 404’ing
- finding whether request is for post, and post id
- more types plugin – display all post of post type on page
- When using Simple Fields plugin, how do I pull the information out of the database to display on a page?
- Any built-in function to associate a post to category through a plugin?
- How to hide some section in WordPress under Post
- Display post lists in 2nd paragraph
- How to make a proper custom post type link
- Can’t delete Draft Post [closed]
- WordPress comments not appearing in blog posts, likely because of Redux template. Could I fix this with a plugin that adds a comment form as a block? [closed]
- Custom post type – no layout section of Document tab, and no author choice
- Creating a custom post type, adding custom meta fields, preventing all future editability of posts of this type
- ‘No Results Found’ on single post for custom post type
- Keep a post copy when this one is updated – issue
- WordPress display breadcrumbs using Yoast plugin [closed]
- Outbound link autometic converted into linkdirect , and not opening
- Making a Template for a CPT created by a plugin
- how to add a button next to the wordpress view button?
- Display by Category in Admin
- auto populate list of questions if user select a category xyz
- Preg Match All doesn’t Allow echo first character for WordPress Taxonomy Tags
- How to allow an editor to edit all WordPress blog posts but have the last say as administrator?
- Two problems on my WordPress installation [closed]
- posts comments goes to trash
- Contributive page where people logged in can write