Skip to content

Commit c1d61b8

Browse files
authored
Fix excluded categories in latest-posts (#699)
1 parent bd680af commit c1d61b8

File tree

1 file changed

+20
-18
lines changed

1 file changed

+20
-18
lines changed

functions/latest-posts.php

+20-18
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,43 @@
1515
* @return WP_Query
1616
*/
1717
function sunflower_get_latest_posts( $number = -1, $category_ids = null, $exclude_ids = null ) {
18-
$tax_query = null;
18+
$tax_query = array();
1919

20-
if ( $category_ids || $exclude_ids ) {
20+
if ( $exclude_ids ) {
21+
array_push(
22+
$tax_query,
23+
array(
24+
'taxonomy' => 'category',
25+
'field' => 'slug',
26+
'operator' => 'NOT IN',
27+
'terms' => $exclude_ids,
28+
)
29+
);
30+
}
31+
32+
if ( $category_ids ) {
2133
// In sunflower < 2.1.0, category_ids is a comma separated string.
2234
if ( ! is_array( $category_ids ) ) {
2335
$category_ids = explode( ',', $category_ids );
2436
}
2537

2638
if ( sunflower_is_numeric_array( $category_ids ) ) {
27-
$tax_query = array(
39+
array_push(
40+
$tax_query,
2841
array(
2942
'taxonomy' => 'category',
3043
'field' => 'id',
3144
'terms' => $category_ids,
32-
),
33-
array(
34-
'taxonomy' => 'category',
35-
'field' => 'slug',
36-
'operator' => 'NOT IN',
37-
'terms' => $exclude_ids,
38-
),
45+
)
3946
);
4047
} else {
41-
$tax_query = array(
48+
array_push(
49+
$tax_query,
4250
array(
4351
'taxonomy' => 'category',
4452
'field' => 'slug',
4553
'terms' => $category_ids,
46-
),
47-
array(
48-
'taxonomy' => 'category',
49-
'field' => 'slug',
50-
'operator' => 'NOT IN',
51-
'terms' => $exclude_ids,
52-
),
54+
)
5355
);
5456
}
5557
}

0 commit comments

Comments
 (0)