|
15 | 15 | * @return WP_Query
|
16 | 16 | */
|
17 | 17 | function sunflower_get_latest_posts( $number = -1, $category_ids = null, $exclude_ids = null ) {
|
18 |
| - $tax_query = null; |
| 18 | + $tax_query = array(); |
19 | 19 |
|
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 ) { |
21 | 33 | // In sunflower < 2.1.0, category_ids is a comma separated string.
|
22 | 34 | if ( ! is_array( $category_ids ) ) {
|
23 | 35 | $category_ids = explode( ',', $category_ids );
|
24 | 36 | }
|
25 | 37 |
|
26 | 38 | if ( sunflower_is_numeric_array( $category_ids ) ) {
|
27 |
| - $tax_query = array( |
| 39 | + array_push( |
| 40 | + $tax_query, |
28 | 41 | array(
|
29 | 42 | 'taxonomy' => 'category',
|
30 | 43 | 'field' => 'id',
|
31 | 44 | 'terms' => $category_ids,
|
32 |
| - ), |
33 |
| - array( |
34 |
| - 'taxonomy' => 'category', |
35 |
| - 'field' => 'slug', |
36 |
| - 'operator' => 'NOT IN', |
37 |
| - 'terms' => $exclude_ids, |
38 |
| - ), |
| 45 | + ) |
39 | 46 | );
|
40 | 47 | } else {
|
41 |
| - $tax_query = array( |
| 48 | + array_push( |
| 49 | + $tax_query, |
42 | 50 | array(
|
43 | 51 | 'taxonomy' => 'category',
|
44 | 52 | 'field' => 'slug',
|
45 | 53 | 'terms' => $category_ids,
|
46 |
| - ), |
47 |
| - array( |
48 |
| - 'taxonomy' => 'category', |
49 |
| - 'field' => 'slug', |
50 |
| - 'operator' => 'NOT IN', |
51 |
| - 'terms' => $exclude_ids, |
52 |
| - ), |
| 54 | + ) |
53 | 55 | );
|
54 | 56 | }
|
55 | 57 | }
|
|
0 commit comments