WordPress.org

Ready to get started?Download WordPress

Forums

[Plugin: Microkid's Related Posts] Using variable from other function (3 posts)

  1. Tim-dpi
    Member
    Posted 5 years ago #

    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 );
    
    			}
    		}
    	}
  2. microkid
    Member
    Posted 5 years ago #

    Hi Tim,

    Can you explain a little more what it is exactly that you are trying to establish?

    regards,
    M.

  3. Tim-dpi
    Member
    Posted 5 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.