Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function psi_get_playlists_by_user( $user_id, $excluded_playlists_game_id = 0 ) {
- error_log( "psi_get_playlists_by_user() called" );
- if ( false !== $user_id && is_numeric( $user_id ) && 0 < $user_id ) {
- $output = get_transient( 'user_playlists_' . $user_id );
- if ( false === $output ) {
- $args = array(
- 'post_type' => PSiCorePostTypes::PLAYLISTS,
- 'post_status' => 'publish',
- 'author' => $user_id,
- 'order_by' => 'title',
- 'order' => 'ASC',
- 'suppress_filters ' => false,
- );
- # Get the user playlist IDs that already have this game saved in
- if ( is_numeric( $excluded_playlists_game_id ) && 0 < $excluded_playlists_game_id ) {
- $excluded_playlists_args = array(
- 'meta_query' => array(
- array(
- 'key' => 'psi_playlist_games_$_item',
- 'compare' => '!=',
- 'value' => $excluded_playlists_game_id,
- ),
- ),
- );
- $args = array_merge( $args, $excluded_playlists_args );
- }
- # Get playlists
- $user_playlists = new WP_Query( $args );
- error_log( 'exdluded game ID: ' . $excluded_playlists_game_id );
- error_log( 'Found posts: ' . $user_playlists->found_posts );
- if ( $user_playlists ) {
- $output = $user_playlists;
- } else {
- $output = [];
- }
- set_transient( 'user_playlists_' . $user_id, $output, 5 );
- //set_transient( 'user_playlists_' . $user_id, $output, DAY_IN_SECONDS );
- }
- } else {
- return false;
- }
- return $output;
- }
- add_filter( 'posts_where', 'get_user_playlists_by_user_posts_where' );
- function get_user_playlists_by_user_posts_where( $where ) {
- $where = str_replace( "meta_key = 'psi_playlist_games_$", "meta_key LIKE 'psi_playlist_games_%", $where );
- return $where;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement