Beee

edited query with %

Oct 28th, 2020 (edited)
1,153
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $excluded_playlists_game_id = 4;
  2.  
  3. $query_args = array(
  4.     'posts_per_page' => -1,
  5.     'post_type'      => 'xxx',
  6.     'meta_query'     => array(
  7.         'key'     => 'psi_playlist_games_$_psi_playlist_item',
  8.         'value'   => $excluded_playlists_game_id,
  9.         'compare' => '!=',
  10.     ),
  11. );
  12.  
  13. function playlist_filter( $where ) {
  14.     global $wpdb;
  15.     $where = str_replace(
  16.         "meta_key = 'sd_tour_schedule_$",
  17.         "meta_key LIKE 'sd_tour_schedule_%",
  18.         $wpdb->remove_placeholder_escape($where)
  19.     );
  20.     return $where;
  21. }
  22.  
  23. add_filter( 'posts_where', 'playlist_filter' );
  24. $posts = get_posts( $query_args );
  25. remove_filter( 'posts_where', 'playlist_filter' );
  26.  
RAW Paste Data