Issue : the problem comes into play when I try to add in more than one tags.
For example :
$args=array( 'page-tags' => "basic tag, 2nd tag" , 'post_type' => 'page', //'post_status' => 'publish', //'posts_per_page' => -1, 'caller_get_posts'=> 1 );
Then nothing is return in the query. I've also tried using 'page-tags' => array('basic tag', '2nd tag') and that still doesn't work.
So my question is, how can I use an OR for the taxonomy ?
Solution : I believe this can handle your "OR" of page tags :
add_filter('posts_where','my_posts_where',10,2 );
function my_posts_where( $sql_where,$query ) {
global $wpdb;
if (!empty($query->query['page-tags'])) {
$page_tags = explode(',',$query->query['page-tags']);
$slug_templates = implode(',',array_fill(0,count($page_tags),'%s'));
$add_where = <<<SQL
AND {$wpdb->posts}.ID IN (SELECT tr.object_id
FROM {$wpdb->term_relationships} tr INNER JOIN {$wpdb->term_taxonomy} tt ON tr.term_taxonomy_id = tt.term_taxonomy_id
INNER JOIN wp_terms t ON t.term_id = tt.term_id WHERE t.slug IN ($slug_templates))
SQL;
$add_where = $wpdb->prepare($add_where,$page_tags);
}
return "$sql_where $add_where ";
}

This work by maniac.vardhan is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License.
0 comments :: query taxonomy in pages : how to use an or for the taxanomy ?
Post a Comment