Difficult to explain and maybe totally impossible but I have say 30 tags in total. I would like to output all posts that contain at least one from a list of say 10 tags but do not contain any of the other 20.
So for example (assuming I'm targeting posts exclusively containing any number of tags one - ten):
Post containing tags: one three eight ten - would be output Post containing tags: one three eight ten twelve - would not be output
When I say output it could be a list to include in a post or a unique post / page with its own template. The output method I am flexible with - it's targeting the posts I'm not sure can be done? I am only talking about the tag taxonomy - no other variables.
========================================
Update 16 Jan 2014:
I have created a new template, the relevant parts of which are:
$args = array(
'post_type' => 'post',
'posts_per_page' => 12,
'paged' => $paged,
'tag__in' => array (46, 5, 101, 22, 122, 7, 102, 15, 104, 47, 105, 66, 43, 123),
'tag__not_in' => array (10,121,20,36,23,24,21,76,82,17,6,106,8,75,54,38,57,86,56,95,25,62,16,39,40,69,37,9,42,41,87,73,85)
);
$wp_query = null;
$wp_query = new WP_Query();
$wp_query -> query($args);
?>
<?php if ( $wp_query->have_posts() ) : ?>
<?php while ( $wp_query->have_posts() ) : $wp_query->the_post(); ?>
<?php get_template_part('includes/format', 'archive-update'); ?>
<?php endwhile; ?>
<?php endif; ?>
This works well - the issue is that the tag__in
array will be static but the tag__not_in
could be dynamic as new tags are added. I would like to automate this array (if that is the correct phrase). To grab the tag ids quickly for tag__not_in
I created another template with the following code:
$tags = get_tags('exclude=46,5,101,22,122,7,102,15,104,47,105,66,43,123');
$html = '<div class="post_tags">';
foreach ( $tags as $tag ) {
$html .= "{$tag->term_id},";
}
$html .= '</div>';
echo $html;
and then copied and pasted the displayed ids manually into the tag__not_in
array.
Basically how can I adapt the line:
'tag__not_in' => array (10,121,20,36,23,24,21,76,82,17,6,106,8,75,54,38,57,86,56,95,25,62,16,39,40,69,37,9,42,41,87,73,85)
so that the ids are automatically populated by the array created by get_tags(exclude...)
. I hope that makes sense.
The output page is http://skipology.com/iphone-photography-articles-10-essential-apps/
$query = new WP_Query( array( 'tag__in' => array( 37, 47 ) ) );
for the tags I want included combined with:$query = new WP_Query( array( 'tag__not_in' => array( 37, 47 ) ) );
to ensure the posts don't also have other tags but: 1. How do I combine them in to a single query 2. Re the tag__not_in array is there any way to say all except those listed in the tag__in array? If I list manually I would need to update the code if new tags are added! codex.wordpress.org/Class_Reference/WP_Query#Tag_Parameters$tags = get_tags('exclude=46,5,101,22,122,7,102,15,104,47,105,66,43,123');
to return all the tags except those listed. I've then tried to insert the variable into my code via...'tag__not_in' => $tags
but it doesn't work. I think this is my inexperience in coding and is missing a step or two to get tag not in to recognise what $tags is. Not sure.