Last active
June 5, 2018 19:37
-
-
Save DevWael/98c6c7add0695774db5b470283af8612 to your computer and use it in GitHub Desktop.
Get Post Ids of Liked from user which is not saved in user meta and cannot be get by get_user_meta() function Works with plugin (WP ULike) https://wordpress.org/plugins/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 | |
//Works only with wordpress plugin (WP ULike) url: https://wordpress.org/plugins/wp-ulike/ | |
function prefix_get_posts_liked_by_current_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; | |
} | |
} | |
//simple use: | |
$arguments = array( | |
'post__in' => prefix_get_posts_liked_by_current_user(get_current_user_id()) | |
); | |
$user_query = new WP_Query($arguments); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment