> Anthony Moore wrote:
> I just realized that the page is displaying ALL of the posts and not just the ones with a term in the "celebrities" taxonomy.
> I guess "taxonomy_name" doesn't do anything. These is my args
> Any suggestions?
Hi Anthony, I can't reply on the completed question (closed for comments):
http://www.wpquestions.com/question/showChronoLoggedIn/id/7681
You are right, I just checked out the SQL query behind it.
For example:
'taxonomy'=>'celebrity_types',
'taxonomy_name'=>'celebrity_types',
'tax_query' => array(
array(
'taxonomy' => 'celebrity_types',
)
)
does not change the query at all.
There are few alternative ideas that come to mind:
1) if the terms are not many, you can list them like this:
'tax_query' => array(
array(
'taxonomy' => 'celebrity_types',
'field' => 'slug',
'terms' => array('type_a','type_b','type_c'),
'operator' => 'IN',
)
)
2) you can have one term (fx. "all") that all "speakers" posts are marked with, if they are in the celebrity_types taxonomy, then you can use
'tax_query' => array(
array(
'taxonomy' => 'celebrity_types',
'field' => 'slug',
'terms' => 'all'
)
)
3) have one term (fx. "exclude") that all speakers posts are marked with if they are
NOT in the celebrity_types taxonomy (but then they will be in this taxonomy of coz ;-).
You can then use:
'tax_query' => array(
array(
'taxonomy' => 'celebrity_types',
'field' => 'slug',
'terms' => array('exclude'),
'operator' => 'NOT IN',
)
)
4) use custom SQL queries like this one:
(to search for all posts in the "speakers" post_type that are also in the "celebrity_types" taxonomy)
$sql=" SELECT
{$wpdb->term_relationships}.object_id as post_id,
{$wpdb->posts}.post_title as post_title,
{$wpdb->terms}.name as term_name,
{$wpdb->term_taxonomy}.term_id as term_id,
{$wpdb->term_taxonomy}.taxonomy,
{$wpdb->terms}.slug as term_slug,
{$wpdb->posts}.post_name
FROM {$wpdb->terms}
LEFT JOIN {$wpdb->term_taxonomy}
ON {$wpdb->term_taxonomy}.term_id = {$wpdb->terms}.term_id
LEFT JOIN {$wpdb->term_relationships}
ON {$wpdb->term_taxonomy}.term_taxonomy_id = {$wpdb->term_relationships}.term_taxonomy_id
LEFT JOIN {$wpdb->posts}
ON {$wpdb->term_relationships}.object_id = {$wpdb->posts}.id
WHERE {$wpdb->term_taxonomy}.taxonomy in ( 'celebrity_types')
AND {$wpdb->posts}.post_status ='publish'
AND {$wpdb->posts}.post_type ='speakers'
GROUP BY post_id LIMIT 0,6
";
$data =$wpdb->get_results($sql,ARRAY_A);
// debug:
// echo "count: ".count($data);
// print_r($data);
foreach($data as $d){
echo "<div>";
echo "<h2>".$d['post_title']."</h2>";
echo $d['post_name'];
echo "</div>";
}
but this is the most complex method and will need some more programming to link fx. $paged with the "LIMIT" part of the query.
You would also have to change the pagination and next/prev links.
cheers.