SHOW:
|
|
- or go back to the newest paste.
| 1 | - | function psi_get_playlists_by_user( $user_id, $excluded_playlists_game_id = 0 ) {
|
| 1 | + | $excluded_playlists_game_id = 4; |
| 2 | ||
| 3 | - | error_log( "psi_get_playlists_by_user() called" ); |
| 3 | + | $query_args = array( |
| 4 | 'posts_per_page' => -1, | |
| 5 | - | if ( false !== $user_id && is_numeric( $user_id ) && 0 < $user_id ) {
|
| 5 | + | 'post_type' => 'xxx', |
| 6 | - | $output = get_transient( 'user_playlists_' . $user_id ); |
| 6 | + | 'meta_query' => array( |
| 7 | - | if ( false === $output ) {
|
| 7 | + | 'key' => 'psi_playlist_games_$_psi_playlist_item', |
| 8 | - | $args = array( |
| 8 | + | 'value' => $excluded_playlists_game_id, |
| 9 | - | 'post_type' => PSiCorePostTypes::PLAYLISTS, |
| 9 | + | 'compare' => '!=', |
| 10 | - | 'post_status' => 'publish', |
| 10 | + | ), |
| 11 | - | 'author' => $user_id, |
| 11 | + | ); |
| 12 | - | 'order_by' => 'title', |
| 12 | + | |
| 13 | - | 'order' => 'ASC', |
| 13 | + | function playlist_filter( $where ) {
|
| 14 | - | 'suppress_filters ' => false, |
| 14 | + | global $wpdb; |
| 15 | - | ); |
| 15 | + | $where = str_replace( |
| 16 | "meta_key = 'sd_tour_schedule_$", | |
| 17 | - | # Get the user playlist IDs that already have this game saved in |
| 17 | + | "meta_key LIKE 'sd_tour_schedule_%", |
| 18 | - | if ( is_numeric( $excluded_playlists_game_id ) && 0 < $excluded_playlists_game_id ) {
|
| 18 | + | $wpdb->remove_placeholder_escape($where) |
| 19 | - | $excluded_playlists_args = array( |
| 19 | + | ); |
| 20 | - | 'meta_query' => array( |
| 20 | + | return $where; |
| 21 | - | array( |
| 21 | + | } |
| 22 | - | 'key' => 'psi_playlist_games_$_item', |
| 22 | + | |
| 23 | - | 'compare' => '!=', |
| 23 | + | add_filter( 'posts_where', 'playlist_filter' ); |
| 24 | - | 'value' => $excluded_playlists_game_id, |
| 24 | + | $posts = get_posts( $query_args ); |
| 25 | - | ), |
| 25 | + | remove_filter( 'posts_where', 'playlist_filter' ); |
| 26 | - | ), |
| 26 | + |