Advertisement
Guest User

Untitled

a guest
Sep 5th, 2013
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.22 KB | None | 0 0
  1. <?php
  2.  
  3. class Contractor_model
  4. {
  5.  
  6.     function get_ids_from_tax($taxonomy, $taxarray, $operator="IN")
  7.     {
  8.         global $wp_query;
  9.         $args = array(
  10.                 'post_type' => 'contractors',
  11.                 'posts_per_page' => -1,
  12.                 'tax_query' => array(
  13.                     array(
  14.                         'taxonomy' => $taxonomy,
  15.                         'terms' => $taxarray,
  16.                         'field' => 'id'
  17.                     )
  18.                 )
  19.             );
  20.         $query = new WP_Query($args);
  21.  
  22.         // The Loop
  23.         if ( $query->have_posts() ) {
  24.             $return=array();
  25.             while ( $query->have_posts() ) {
  26.                 $query->the_post();
  27.                 $in_tax_array = false;
  28.                 foreach($taxarray as $taxarray)
  29.                 {
  30.                     if ($taxarray==get_the_ID()) {$in_tax_array=true;}
  31.                 }
  32.                 if ($in_tax_array==true) {
  33.                     $return = array_merge($return, array(get_the_ID()));
  34.                 }
  35.                
  36.             }
  37.             return $return;
  38.         } else {
  39.             return array();
  40.         }
  41.         wp_reset_postdata();
  42.     }
  43.    
  44.    
  45.  
  46.  
  47. }
  48.  
  49.  
  50. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement