Title: [Plugin: Microkid&#8217;s Related Posts] Using variable from other function
Last modified: August 19, 2016

---

# [Plugin: Microkid’s Related Posts] Using variable from other function

 *  [tim-dpi](https://wordpress.org/support/users/tim-dpi/)
 * (@tim-dpi)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/plugin-microkids-related-posts-using-variable-from-other-function/)
 * Hi there,
 * I’m pretty new with WordPress and I have a question about plugin: Microkid’s 
   Related Posts.
    I’ve added an extra field in db table ‘wp_post_relationships’
   so I can separate different related posts. The variable $related_post_title is
   uses in other functions of this plugin. Therefore I want to use $related_post_title
   to help me do this. However, $related_post_title seems to be empty in the function
   where i’m trying to use it. I works when I fill $related_post_title manually.
 * Here is my code.. How can I use $related_post_title in this function?
 *     ```
       function MRP_save_relationships( $post_id, $related_posts, $related_post_title ) {
   
       		global $wpdb;
   
       			// First delete the relationships that were there before
   
       		MRP_delete_relationships( $post_id ); 
   
       			// Now add/update the relations
       		if( $related_posts ) {
       			foreach( $related_posts as $related_post) {					
   
       				if($related_post_title == "something"){
       					$relation_type = 2;
       				}
       				else{
       					$relation_type = 1;
       				} 	
   
       				$related_post = (int) $related_post;
       				$query = "INSERT INTO ".$wpdb->prefix."post_relationships VALUES( $post_id, $related_post, $relation_type)";
       				$result = $wpdb->query( $query );
   
       			}
       		}
       	}
       ```
   

Viewing 2 replies - 1 through 2 (of 2 total)

 *  [microkid](https://wordpress.org/support/users/microkid/)
 * (@microkid)
 * [16 years, 12 months ago](https://wordpress.org/support/topic/plugin-microkids-related-posts-using-variable-from-other-function/#post-1094174)
 * Hi Tim,
 * Can you explain a little more what it is exactly that you are trying to establish?
 * regards,
    M.
 *  Thread Starter [tim-dpi](https://wordpress.org/support/users/tim-dpi/)
 * (@tim-dpi)
 * [16 years, 11 months ago](https://wordpress.org/support/topic/plugin-microkids-related-posts-using-variable-from-other-function/#post-1094257)
 * Hi Microkid,
 * I want to extend your plugin with the option ‘Relationship type’. So you can 
   select what kind of relation your related post is. This relationship type can
   be used only show related posts from a specific relationship type.
 * In other words, I want to categorize the related posts
 * I see your location is Amsterdam, are you Dutch?

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘[Plugin: Microkid’s Related Posts] Using variable from other function’
is closed to new replies.

 * 2 replies
 * 2 participants
 * Last reply from: [tim-dpi](https://wordpress.org/support/users/tim-dpi/)
 * Last activity: [16 years, 11 months ago](https://wordpress.org/support/topic/plugin-microkids-related-posts-using-variable-from-other-function/#post-1094257)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
