Limiting taxonomy term results to specific term IDs only

Limiting category, post tag, and other taxonomy term results to specific IDs only

What is this, and where do I put this custom code?

add_filter('asp_term_query_add_where', 'asp_term_query_add_where_include', 10, 3);
function asp_term_query_add_where_include($args, $s, $s_arr) {
	$ids = '1, 2, 3, 4';  // Enter the taxonomy term IDs here to include

	// -- DO NOT CHANGE BELOW THIS LINE --
	global $wpdb;
	$ids = explode(',', $ids);
	foreach ( $ids as $k => &$id ) {
		$id = trim($id);
		if ( $id == '' ) {
			unset($ids[$k]);
		}
	}
	if ( count($ids) > 0 ) {
	  return " AND ($wpdb->terms.term_id IN (" .implode(",", $ids). "))";
	}

	return '';
}
  • $ids - comma separated list of taxonomy term IDs to restrict the results to

Last updated