65 | | } |
66 | | No newline at end of file |
| 65 | |
| 66 | /** |
| 67 | * @ticket 25284 |
| 68 | */ |
| 69 | function test_term_taxonomy_id_field_no_taxonomy() { |
| 70 | $posts = $this->factory->post->create_many( 5 ); |
| 71 | |
| 72 | $cats = $tags = array(); |
| 73 | |
| 74 | // need term_taxonomy_ids in addition to term_ids, so no factory |
| 75 | for ( $i = 0; $i < 5; $i++ ) { |
| 76 | $cats[$i] = wp_insert_term( 'category-' . $i , 'category' ); |
| 77 | $tags[$i] = wp_insert_term( 'tag-' . $i, 'post_tag' ); |
| 78 | |
| 79 | // post 0 gets all terms |
| 80 | wp_set_object_terms( $posts[0], array( $cats[$i]['term_id'] ), 'category', true ); |
| 81 | wp_set_object_terms( $posts[0], array( $tags[$i]['term_id'] ), 'post_tag', true ); |
| 82 | } |
| 83 | |
| 84 | wp_set_object_terms( $posts[1], array( $cats[0]['term_id'], $cats[2]['term_id'], $cats[4]['term_id'] ), 'category' ); |
| 85 | wp_set_object_terms( $posts[1], array( $tags[0]['term_id'], $tags[2]['term_id'], $cats[4]['term_id'] ), 'post_tag' ); |
| 86 | |
| 87 | wp_set_object_terms( $posts[2], array( $cats[1]['term_id'], $cats[3]['term_id'] ), 'category' ); |
| 88 | wp_set_object_terms( $posts[2], array( $tags[1]['term_id'], $tags[3]['term_id'] ), 'post_tag' ); |
| 89 | |
| 90 | wp_set_object_terms( $posts[3], array( $cats[0]['term_id'], $cats[2]['term_id'], $cats[4]['term_id'] ), 'category' ); |
| 91 | wp_set_object_terms( $posts[3], array( $tags[1]['term_id'], $tags[3]['term_id'] ), 'post_tag' ); |
| 92 | |
| 93 | $results = $this->q->query( array( |
| 94 | 'fields' => 'ids', |
| 95 | 'orderby' => 'id', |
| 96 | 'order' => 'ASC', |
| 97 | 'tax_query' => array( |
| 98 | 'relation' => 'OR', |
| 99 | array( |
| 100 | 'field' => 'term_taxonomy_id', |
| 101 | 'terms' => array( $cats[0]['term_taxonomy_id'], $cats[2]['term_taxonomy_id'], $cats[4]['term_taxonomy_id'], $tags[0]['term_taxonomy_id'], $tags[2]['term_taxonomy_id'], $cats[4]['term_taxonomy_id'] ), |
| 102 | 'operator' => 'AND', |
| 103 | 'include_children' => false, |
| 104 | ), |
| 105 | array( |
| 106 | 'field' => 'term_taxonomy_id', |
| 107 | 'terms' => array( $cats[1]['term_taxonomy_id'], $cats[3]['term_taxonomy_id'], $tags[1]['term_taxonomy_id'], $tags[3]['term_taxonomy_id'] ), |
| 108 | 'operator' => 'AND', |
| 109 | 'include_children' => false, |
| 110 | ) |
| 111 | ) |
| 112 | ) ); |
| 113 | |
| 114 | $this->assertEquals( array( $posts[0], $posts[1], $posts[2] ), $results, 'Relation: OR; Operator: AND' ); |
| 115 | |
| 116 | $results = $this->q->query( array( |
| 117 | 'fields' => 'ids', |
| 118 | 'orderby' => 'id', |
| 119 | 'order' => 'ASC', |
| 120 | 'tax_query' => array( |
| 121 | 'relation' => 'AND', |
| 122 | array( |
| 123 | 'field' => 'term_taxonomy_id', |
| 124 | 'terms' => array( $cats[0]['term_taxonomy_id'], $tags[0]['term_taxonomy_id'] ), |
| 125 | 'operator' => 'IN', |
| 126 | 'include_children' => false, |
| 127 | ), |
| 128 | array( |
| 129 | 'field' => 'term_taxonomy_id', |
| 130 | 'terms' => array( $cats[3]['term_taxonomy_id'], $tags[3]['term_taxonomy_id'] ), |
| 131 | 'operator' => 'IN', |
| 132 | 'include_children' => false, |
| 133 | ) |
| 134 | ) |
| 135 | ) ); |
| 136 | |
| 137 | $this->assertEquals( array( $posts[0], $posts[3] ), $results, 'Relation: AND; Operator: IN' ); |
| 138 | } |
| 139 | } |