Support » Plugin: BuddyPress Like » [Plugin: BuddyPress Like] Make or show something if the POST is Liked by the user!

  • Hi! Thanks for the plugin it’s very useful!
    I want to show or make something only if the post is liked by the user. Is something like that:

    if(THE_USER_LIKE_POST) {
    DO THIS
    }else{
    DO THIS
    }

    I want to do it for example in the single.php, i want a function that do that is it possible?

Viewing 1 replies (of 1 total)
  • Thread Starter juanpons14

    (@juanpons14)

    Well i can do it with this code finally:

    global $current_user, $post;
                $post_id = $post->ID;
                $user_id = $current_user->ID;
                $mi_serie = get_post_meta($post_id,'serie',true);
    	    $id_serie = wt_get_ID_by_page_name($mi_serie);
    	    $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
    		if($user_likes[$id_serie] !='') {
                    DO SOMETHING
                    }

    What this code does is:
    Make something if the user LIKE the NAME of the post that is in the value of the ‘serie’ meta_key. The meta_value of serie must be a Name of page or post.

    The wt_get_ID_by_page_name($mi_serie); function is a custom function that it isn’t in wordpress. Retrieve the post/page ID with its Name.
    Put this in your functions.php that it’s in your actual theme.

    function wt_get_ID_by_page_name($page_name)
    {
    	global $wpdb;
    	$page_name_id = $wpdb->get_var("SELECT ID FROM $wpdb->posts WHERE post_title = '".$page_name."'");
    	return $page_name_id;
    }

    If you only want to do something if the actual post is liked, for example to use it in single.php or page.php you can use this code:

    global $current_user, $post;
                $post_id = $post->ID;
                $user_id = $current_user->ID;
    	    $user_likes = get_user_meta( $user_id, 'bp_liked_blogposts', true );
    		if($user_likes[$post_id] !='') {
                    DO SOMETHING
                    }else{
                    DO IF DON'T LIKE
                    }
Viewing 1 replies (of 1 total)
  • The topic ‘[Plugin: BuddyPress Like] Make or show something if the POST is Liked by the user!’ is closed to new replies.