php - Get posts that matches both taxonomies -


i have movie-database, want know movies actor , b has both been featured in.

function getmoviefromactor(){ global $wp_query; global $wpdb; global $post; $loop = new wp_query(array( 'post_type' => 'movies', 'actors' => 'a', 'b', 'posts_per_page' =>-1, ));  print_r($loop); while ( $loop->have_posts() ) : $loop->the_post();   ?>  <h2 class="entry-title"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'permalink %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a></h2>             <?php the_content(); endwhile; } 

the problem code wordpress default searching actor or b , displaying every movie they've been featured in , not movie(s) they've both been featured in.

thanks, marten


edit: think im there, im stuck in sql-query, works perfect if search 1 of actors, problem accors when search both, results in empty array.

when manual search in sql query see duplicate content different term.slugs, there workaround this?

global $wpdb;   $querystr = "                 select *                  $wpdb->posts                 left join $wpdb->term_relationships on($wpdb->posts.id = $wpdb->term_relationships.object_id)                 left join $wpdb->term_taxonomy on($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)                 left join $wpdb->terms on($wpdb->term_taxonomy.term_id = $wpdb->terms.term_id)                 $wpdb->posts.post_type = 'movies'                 , $wpdb->posts.post_status = 'publish'                 , $wpdb->term_taxonomy.taxonomy = 'actors'                 , $wpdb->terms.slug = 'a'                 , $wpdb->terms.slug = 'b'                 order $wpdb->posts.post_date desc";         $pageposts = $wpdb->get_results($querystr, object); print_r($pageposts); 

all best, marten

try this:

'actors' => array('a', 'b') 

Comments

Popular posts from this blog

android - Spacing between the stars of a rating bar? -

html - Instapaper-like algorithm -

c# - How to execute a particular part of code asynchronously in a class -