Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions RandomPostOnRefresh.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
),
);
}
}
Expand Down Expand Up @@ -371,4 +374,4 @@ public static function error( $message, $example = '' ) {

add_action( 'plugins_loaded', array( 'RandomPostOnRefresh', 'initialize' ) );

}
}
21 changes: 21 additions & 0 deletions tests/RandomPostOnRefreshTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Loading