Guest User

Untitled

a guest
Sep 5th, 2013
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 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.         return $query;  
  23.     wp_reset_postdata();
  24.    }
  25.  
  26. }
  27.  
  28. $contractor = new Contractor_model();
  29. print_r($contrator->get_ids_from_tax('service_type', '$_GET['service_type']'));
  30.  
  31. //$_GET['service_type'] returns the following:
  32. //Array ( [0] => 24 )
  33. //id #24 for the custom taxonomy service_type does exist, and it has 2 contractors attached to it
  34.  
  35. ?>
Advertisement
Add Comment
Please, Sign In to add comment