Created
March 11, 2019 10:20
-
-
Save DevWael/c43a18d5e6fd029e2a7f75fb37c209ac to your computer and use it in GitHub Desktop.
get user liked posts (IDs) with plugin (WP Ulike)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function dw_get_posts_liked_by_user( $user_ID = '' ) { | |
if ( function_exists( 'wp_ulike' ) ) { | |
global $wpdb; | |
$result = array(); | |
if ( ! $user_ID ) { | |
$user_ID = get_current_user_id(); | |
} | |
$likes = $wpdb->get_results( " | |
SELECT U.post_id | |
FROM " . $wpdb->prefix . "ulike AS U | |
WHERE U.user_id = $user_ID AND U.status = 'like' | |
GROUP BY U.post_id | |
ORDER BY MAX(U.date_time) DESC | |
" ); | |
if ( $likes !== 0 ) { | |
foreach ( $likes as $like ) { | |
$result[] = $like->post_id; | |
} | |
} | |
return $result; | |
} else { | |
return false; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment