Limiting taxonomy term results to specific term IDs only
Limiting category, post tag, and other taxonomy term results to specific IDs only
1
add_filter('asp_term_query_add_where', 'asp_term_query_add_where_include', 10, 3);
2
function asp_term_query_add_where_include($args, $s, $s_arr) {
3
$ids = '1, 2, 3, 4'; // Enter the taxonomy term IDs here to include
4
5
// -- DO NOT CHANGE BELOW THIS LINE --
6
global $wpdb;
7
$ids = explode(',', $ids);
8
foreach ( $ids as $k => &$id ) {
9
$id = trim($id);
10
if ( $id == '' ) {
11
unset($ids[$k]);
12
}
13
}
14
if ( count($ids) > 0 ) {
15
return " AND ($wpdb->terms.term_id IN (" .implode(",", $ids). "))";
16
}
17
18
return '';
19
}
Copied!
  • $ids - comma separated list of taxonomy term IDs to restrict the results to
Last modified 1yr ago
Copy link