Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am slowly going mad trying to figure this out..

I want to list custom post type 'mobile_review' by custom taxonomy 'mobile_phone', as multipe custom post types share this taxonomy I need some way to segment.

So far I have this:

function get_terms_by_post_type($taxonomies,$args){

 $args = array(
    'post_type' => 'mobile_review'
);

// The query for posts of type 'mobile_review'
$the_query = new WP_Query( $args );

// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();

//get terms    
    //$mobs = wp_get_object_terms($post->ID,"mobile_phone"); 
     $mobs = get_terms('mobile_phone');
 $count = count($terms);
 if ( $count > 0 ){
 echo "<ul>";
 foreach ( $terms as $term ) {
   echo "<li>" . $term->name . "</li>";

 }
 echo "</ul>";
 }

endwhile;

// Reset Post Data
wp_reset_postdata();        

}

Am I close? I have been hacking back and forth for ages and getting nowhere.

Any help would be great! Thanks in advance.

share|improve this question

2 Answers 2

Here's an example that will list all the mobile_review posts that have the term htc_desire_hd in the taxonomy mobile_phone :

$tax_query = array( 'relation' => 'AND' );

$tax_query[] = array( 
    'taxonomy' => 'mobile_phone', 
    'terms' => array('htc_desire_hd'),
    'field' => 'slug' 
);

$args = array(
    'post_type' => 'mobile_review',
    'tax_query' => $tax_query
);

$custom_loop = new WP_Query( $args ); 

if ( $custom_loop->have_posts() ) :

    while( $custom_loop->have_posts() ) : $custom_loop->the_post(); 

            the_title();

    endwhile;

else :

    _e('Sorry, nothing here.');

endif;

wp_reset_query();

Now you can have the phones reviews by phone model, you just need to change the phone names, pass the name from a form, URL, etc.

share|improve this answer
 $args = array(
    'post_type' => 'mobile_review',
    'taxonomy' => 'mobile_phone'
);

Is that what you're looking for?

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.