get_objects_in_term()
git-svn-id: https://develop.svn.wordpress.org/trunk@5585 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
e0bfab53bf
commit
ac1db497fc
@ -859,7 +859,7 @@ class WP_Query {
|
||||
if ( strlen($in_cats) > 0 )
|
||||
$in_cats = " AND $wpdb->term_taxonomy.term_id IN ({$q['cat']}) ";
|
||||
if ( strlen($out_cats) > 0 ) {
|
||||
// TODO
|
||||
// TODO use get_objects_in_term
|
||||
$ids = $wpdb->get_col("SELECT post_id FROM $wpdb->post2cat WHERE $wpdb->post2cat.category_id IN ($out_cats)");
|
||||
if ( is_array($ids) && count($ids > 0) ) {
|
||||
foreach ( $ids as $id )
|
||||
|
@ -366,6 +366,30 @@ function wp_set_object_terms($object_id, $terms, $taxonomy, $append = false) {
|
||||
return $tt_ids;
|
||||
}
|
||||
|
||||
function get_objects_in_term( $terms, $taxonomies, $args = array() ) {
|
||||
global $wpdb;
|
||||
|
||||
if ( !is_array( $terms) )
|
||||
$terms = array($terms);
|
||||
|
||||
if ( !is_array($taxonomies) )
|
||||
$taxonomies = array($taxonomies);
|
||||
|
||||
$defaults = array('order' => 'ASC');
|
||||
$args = wp_parse_args( $args, $defaults );
|
||||
extract($args);
|
||||
|
||||
$taxonomies = "'" . implode("', '", $taxonomies) . "'";
|
||||
$terms = "'" . implode("', '", $terms) . "'";
|
||||
|
||||
$object_ids = $wpdb->get_col("SELECT tr.object_id FROM $wpdb->term_relationships AS tr INNER JOIN $wpdb->term_taxonomy AS tt ON tr.term_taxonomy_id = tt.term_taxonomy_id WHERE tt.taxonomy IN ($taxonomies) AND tt.term_id IN ($in_terms) ORDER BY tr.object_id $order");
|
||||
|
||||
if ( ! $object_ids )
|
||||
return array();
|
||||
|
||||
return $object_ids;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the terms associated with the given object(s), in the supplied taxonomies.
|
||||
* @param int|array $object_id The id of the object(s)) to retrieve for.
|
||||
|
Loading…
Reference in New Issue
Block a user