Title: Linking posts
Last modified: August 19, 2016

---

# Linking posts

 *  [jadedstudio](https://wordpress.org/support/users/jadedstudio/)
 * (@jadedstudio)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/linking-posts/)
 * I have an interesting one. The aim is to be able to link posts using custom fields.
   Here is what I want to do:
 * Create 2 categories, Events & Performers.
 * Add a new post for each performer. These posts will contain performer bio (post
   content), image using custom fields, etc and lie in the performer category.
 * Add a new post for each event. These posts contain information about the event,
   plus information about all performers playing at the event.
 * I thought this may work by adding a custom field to one of the events post called‘
   performer’ and enter the performers name (post title) in there. Do this for all
   performers at that particular event. Then in the events single.php template I
   would need to add a loop which first looks at the custom field ‘performer’, gathers
   all of the names, and matches it to the posts. I then need to display the information
   from each post gathered onto the events post. So now the events post shows info
   for the event, from the_content, and say 3 performer posts showing their bio (
   the_content), image of performer (custom field) etc.
 * Here is a snippet of code I found which I thought would be a good start:
 *     ```
       $key="Distillery";
       $distilleryvalue = get_post_meta($post->ID, $key, true);
       $distilleryvalue = $distilleryvalue . " Distillery";
       $distillery_id = $wpdb->get_row("SELECT * FROM $wpdb->posts WHERE post_title LIKE '%$distilleryvalue%'");
       $distillery_id = $distillery_id->ID;
       $distillery_meta = $wpdb->get_col("SELECT meta_value FROM $wpdb->postmeta WHERE post_id = $distillery_id");
   
       echo 'Distillery';
       echo '';
       echo 'Region: ' . $distillery_meta[3] . '';
       echo 'Country: ' . $distillery_meta[7] . '';
       echo 'Official website';
       echo 'Location (at Google maps)';
       echo 'Buy bootles from this distillery (at the Whisky Exchange)';
       echo 'Read more at Wikipedia';
       echo '';
       ```
   
 * Any help on this would be really much appreciated!! 🙂

Viewing 1 replies (of 1 total)

 *  Thread Starter [jadedstudio](https://wordpress.org/support/users/jadedstudio/)
 * (@jadedstudio)
 * [16 years, 10 months ago](https://wordpress.org/support/topic/linking-posts/#post-1077161)
 * I have found a solution to this and posted it on my blog. You can find out how
   I achieved this here: [http://www.jadedstudio.com/tutorials/linking-wordpress-posts-using-custom-fields](http://www.jadedstudio.com/tutorials/linking-wordpress-posts-using-custom-fields)
 * Hope this helps anyone hoping to achieve the same!

Viewing 1 replies (of 1 total)

The topic ‘Linking posts’ is closed to new replies.

## Tags

 * [custom fields](https://wordpress.org/support/topic-tag/custom-fields/)
 * [linking](https://wordpress.org/support/topic-tag/linking/)
 * [loop](https://wordpress.org/support/topic-tag/loop/)
 * [posts](https://wordpress.org/support/topic-tag/posts/)

 * 1 reply
 * 1 participant
 * Last reply from: [jadedstudio](https://wordpress.org/support/users/jadedstudio/)
 * Last activity: [16 years, 10 months ago](https://wordpress.org/support/topic/linking-posts/#post-1077161)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
