запрос для if num_cat num_cat AND tx term_id IN num_cat else num_cat i

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{ // запрос для 2.3
if ( $num_cat ) $num_cat = "AND tx.term_id IN ($num_cat)";
else $num_cat = '';
if ( $exclude_post ) $exclude_post = "AND p.ID NOT IN($exclude_post) ";
else $exclude_post = '';
if ( $count == 0 ) $count = '';
else $count = 'LIMIT '. $count;
$sortby = 'p.post_date RAND()';
$request = "SELECT DISTINCT p.ID, p.post_title, p.post_date
FROM $wpdb->term_taxonomy tx,
$wpdb->term_relationships tr,
$wpdb->posts p
WHERE
tx.taxonomy='category'
{$num_cat} {$exclude_post}
AND tx.term_taxonomy_id = tr.term_taxonomy_id
AND tr.object_id = p.ID
AND p.post_status = 'publish'
AND p.post_type = 'post'
ORDER BY {$sortby} {$count}";
}