mirror of
https://github.com/WordPress/WordPress.git
synced 2024-11-05 02:10:45 +01:00
get_objects_in_term()
git-svn-id: http://svn.automattic.com/wordpress/trunk@5585 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
283458e631
commit
13a01467dc
@ -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