SELECT distinct `wp_cb_bonuses`.`id_bonus`, `bonus`.`post_title` nume, if(`wp_cb_casinos`.`prioritate` != -3,if(date(`wp_cb_bonuses`.`data_expirare`) >= now(),1,0),0) expirat, if(`wp_cb_casinos`.`prioritate` >= 0,0,-1) low_casino,`wp_cb_casinos`.`prioritate` prioritate_casino, `wp_cb_bonuses`.`post_ID` bonus_post_ID ,data_expirare,`bonus`.`post_date`, `wp_cb_bonuses`.`first_same_casino`,`wp_cb_casinos`.`post_ID` casino_post_ID,`wp_cb_casinos`.`post_review_ID` casino_post_review_ID, `bonus`.`post_modified`,`wp_cb_casinos`.`online`, if(`wp_cb_casinos`.`prioritate` >= 0,page_web_68,99) page_pos,`random`, `wp_cb_bonuses`.`prioritate` `prioritate`, `wp_cb_bonuses`.`ordine` `ordine`, `wp_cb_casinos`.`id_casino`,valid_for,`bonus`.`post_content`, `wp_cb_bonuses`.`id_casino`, `wp_cb_bonuses`.`maximum_cashout`, `wp_cb_bonuses`.`suma`,`wp_cb_bonuses`.`supralink`,`wp_cb_def_tip_bonuses`.`supralink` supralink_tip, `wp_cb_bonuses`.`minimum_depozit`, `wp_cb_casinos`.`maximum_cashout` maximum_cashout_casino, `wp_cb_bonuses`.`procent`,`wp_cb_casinos`.`force_monsterlink`, `wp_cb_casinos`.`minimum_depozit` minimum_depozit_casino,waggering,DATE_FORMAT(data_expirare, '%d/%m/%Y') data_expirare2,`bonus`.`post_modified_gmt`,DATE_FORMAT(post_modified_gmt,'%M %e, %Y') updated, `wp_cb_casinos`.`id_media_logo`,`wp_cb_bonuses`.`id_media`,rating,`wp_cb_bonuses`.`id_tip_bonus`, `wp_cb_bonuses`.`cod_bonus`,`wp_cb_def_tip_bonuses`.`post_ID` type_post_ID ,`wp_cb_def_tip_bonuses`.`nume` bonus FROM wp_cb_bonuses INNER JOIN `wp_cb_def_tip_bonuses` ON `wp_cb_def_tip_bonuses`.`id_tip_bonus`=`wp_cb_bonuses`.`id_tip_bonus` INNER JOIN wp_posts `bonus` on `wp_cb_bonuses`.`post_ID` = `bonus`.`ID` INNER JOIN `wp_cb_casinos` ON `wp_cb_casinos`.`id_casino`=`wp_cb_bonuses`.`id_casino` LEFT JOIN `wp_cb_val_games_bonuses` ON `wp_cb_val_games_bonuses`.`id_bonus` = `wp_cb_bonuses`.`id_bonus` WHERE ( `wp_cb_val_games_bonuses`.`id_def_val_game` = 1 AND `wp_cb_bonuses`.`id_tip_bonus` = 6 ) AND `bonus`.`post_status` ='publish' and app_only = 0 or (if(`wp_cb_casinos`.`prioritate` >= 0,page_web_68,99) < 99 and `bonus`.`post_status` ='publish' and app_only = 0) order by expirat desc, page_pos asc, low_casino desc, `prioritate` desc ,`ordine` desc,`data_expirare`,`post_date` desc limit 0,30