diff --git a/RandomPostOnRefresh.php b/RandomPostOnRefresh.php index 89cb909..1a85d85 100644 --- a/RandomPostOnRefresh.php +++ b/RandomPostOnRefresh.php @@ -280,8 +280,11 @@ public static function build_query_args( $atts ) { $query_args['tag__in'] = $terms; } else { $query_args['tax_query'] = array( - 'taxonomy' => $atts['taxonomy'], - 'terms' => $terms, + array( + 'taxonomy' => $atts['taxonomy'], + 'field' => 'term_id', + 'terms' => $terms, + ), ); } } @@ -371,4 +374,4 @@ public static function error( $message, $example = '' ) { add_action( 'plugins_loaded', array( 'RandomPostOnRefresh', 'initialize' ) ); -} +} \ No newline at end of file diff --git a/tests/RandomPostOnRefreshTest.php b/tests/RandomPostOnRefreshTest.php index f51d307..93e708f 100644 --- a/tests/RandomPostOnRefreshTest.php +++ b/tests/RandomPostOnRefreshTest.php @@ -134,6 +134,27 @@ public function test_build_query_args_with_taxonomy() { $args = RandomPostOnRefresh::build_query_args( $atts ); $this->assertEquals( array( 3, 4 ), $args['category__in'] ); } + + /** + * Test build_query_args with custom taxonomy and terms. + */ + public function test_build_query_args_with_custom_taxonomy() { + $atts = array_merge( + RandomPostOnRefresh::DEFAULT_ATTRIBUTES, + array( + 'post_type' => 'post', + 'taxonomy' => 'custom_tax', + 'terms' => '5,6', + ) + ); + $args = RandomPostOnRefresh::build_query_args( $atts ); + $this->assertArrayHasKey( 'tax_query', $args ); + $this->assertIsArray( $args['tax_query'] ); + $this->assertIsArray( $args['tax_query'][0] ); + $this->assertEquals( 'custom_tax', $args['tax_query'][0]['taxonomy'] ); + $this->assertEquals( 'term_id', $args['tax_query'][0]['field'] ); + $this->assertEquals( array( 5, 6 ), $args['tax_query'][0]['terms'] ); + } /** * Test build_query_args with show=image and image_required=true.