• Hi, the below code is from the widget for displaying recently liked posts by the logged in user. From your file class-wp-ulike-widget.php

    How to use this as a basis to show the same but instead just the likes made by the currently displayed buddypress user? Not logged in user. Ie whose page you are viewing? Using something like bp_displayed_user_id()

    Can you say what to change?
    Thank you

    Your code:

    public function last_posts_liked_by_current_user( $args = array(), $result = '' ) {
    			global $wpdb,$user_ID,$wp_user_IP;
    
    			$defaults = array(
    				"numberOf"    => 10,
    				"period"      => 'all',
    				"sizeOf"      => 32,
    				"trim"        => 10,
    				"profile_url" => '',
    				"show_count"  => true,
    				"show_thumb"  => false,
    				"before_item" => '<li>',
    				"after_item"  => '</li>'
    			);
    			// Parse args
    			$settings 		= wp_parse_args( $args, $defaults );
    			// Extract settings
    			extract($settings);
    
    			$likes = $wpdb->get_results( "
    							SELECT U.post_id, P.meta_value AS counter
    							FROM ".$wpdb->prefix."ulike AS U,
    		                    $wpdb->postmeta AS P
    							WHERE ( U.ip LIKE '$wp_user_IP' OR U.user_id = $user_ID )
    		                    AND U.post_id = P.post_id AND meta_key='_liked'
    							GROUP BY U.post_id
    							ORDER BY MAX(U.date_time) DESC LIMIT $numberOf
    						" );
    
    			if( $likes !== 0 ){
    				foreach ($likes as $like) {
    					$permalink  = get_permalink($like->post_id);
    					$post_title = get_the_title($like->post_id);
    					$post_count = $like->counter;
    					$result .= $before_item;
    					$result .= $show_thumb ? $this->get_post_thumbnail( $like->post_id, $sizeOf ) : '';
    					$result .= '<a href="' . $permalink . '" title="' . $post_title.'" rel="nofollow">' . wp_trim_words( $post_title, $num_words = $trim, $more = null ) . '</a><br/>';
    					$result .= $show_count ? ' <span class="wp_counter_span">'.wp_ulike_format_number( $post_count ).'</span>' : '';
    					$result .= $after_item;
    				}
    			}
    			else{
    					$result .= $before_item;
    					$result .= __( ' No posts liked yet...',WP_ULIKE_SLUG );
    					$result .= $after_item;
    			}
    
    			return $result;
    		}
  • The topic ‘Your widget code – displayed user likes?’ is closed to new replies.