Note that there are some explanatory texts on larger screens.

plurals
  1. POGet posts that matches both taxonomies
    primarykey
    data
    text
    <p>I have a movie-database, i want to know which movies actor A and B has both been featured in. </p> <pre><code>function getmoviefromactor(){ global $wp_query; global $wpdb; global $post; $loop = new WP_Query(array( 'post_type' =&gt; 'movies', 'actors' =&gt; 'A', 'B', 'posts_per_page' =&gt;-1, )); print_r($loop); while ( $loop-&gt;have_posts() ) : $loop-&gt;the_post(); ?&gt; &lt;h2 class="entry-title"&gt;&lt;a href="&lt;?php the_permalink(); ?&gt;" title="&lt;?php printf( esc_attr__( 'Permalink to %s', 'twentyten' ), the_title_attribute( 'echo=0' ) ); ?&gt;" rel="bookmark"&gt;&lt;?php the_title(); ?&gt;&lt;/a&gt;&lt;/h2&gt; &lt;?php the_content(); endwhile; } </code></pre> <p>The problem with this code is that Wordpress by default is searching for Actor A or B and displaying every movie they've been featured in and not just the movie(s) they've both been featured in.</p> <p>Thanks, Marten</p> <hr> <p><strong>EDIT:</strong> I think im almost there, im stuck in a SQL-query, it works perfect if i just search for one of the actors, the problem accors when i search for both, which results in an empty array.</p> <p>When i do the manual search in the SQL query i see duplicate content with different term.slugs, is there any workaround for this? </p> <pre><code>global $wpdb; $querystr = " SELECT * FROM $wpdb-&gt;posts LEFT JOIN $wpdb-&gt;term_relationships ON($wpdb-&gt;posts.ID = $wpdb-&gt;term_relationships.object_id) LEFT JOIN $wpdb-&gt;term_taxonomy ON($wpdb-&gt;term_relationships.term_taxonomy_id = $wpdb-&gt;term_taxonomy.term_taxonomy_id) LEFT JOIN $wpdb-&gt;terms ON($wpdb-&gt;term_taxonomy.term_id = $wpdb-&gt;terms.term_id) WHERE $wpdb-&gt;posts.post_type = 'movies' AND $wpdb-&gt;posts.post_status = 'publish' AND $wpdb-&gt;term_taxonomy.taxonomy = 'actors' AND $wpdb-&gt;terms.slug = 'A' AND $wpdb-&gt;terms.slug = 'B' ORDER BY $wpdb-&gt;posts.post_date DESC"; $pageposts = $wpdb-&gt;get_results($querystr, OBJECT); print_r($pageposts); </code></pre> <p>All the best, Marten</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload