Skip to content

Instantly share code, notes, and snippets.

@DevWael
Created March 11, 2019 10:20
Show Gist options
  • Save DevWael/c43a18d5e6fd029e2a7f75fb37c209ac to your computer and use it in GitHub Desktop.
Save DevWael/c43a18d5e6fd029e2a7f75fb37c209ac to your computer and use it in GitHub Desktop.
get user liked posts (IDs) with plugin (WP Ulike)
<?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