Specific Tag and Category query withpermalink

Hello,

I need to display archive post of a specific category with a specific tag and would like to be able to get the permalink to it, so I can link it to some text if possible. Is this possible?

Thanks

Yes it is possible, though how many times will you be doing it? You may need to make a custom page with a custom search.

http://www.sitepoint.com/forums/showthread.php?825983-Custom-query-for-Wordpress-help-please.

It would be better to create a custom page template as Rhys stated. You would set up a loop like


<?php

   if ( have_posts() ) : while ( have_posts() ) : the_post();
   if{ in_category(XXX) && get_the_terms($post->ID,'xxx'){
   //do stuff
  }
  endwhile; endif; ?>

Hi,

Thanks a lot for the responses and suggestions.

How would I set it to work with multiple categories and tags. I need each page to have a permalink that is associated with its specific category and associated tags and I was hoping to just use one page template or the archive.php. As of now, I have to create a custom page template with the query you suggested so I can query each
category and tag. This method I will have to create 100+ page templates and queries. Or I can use

<?php
if( is_page('##') {
    // custom loop , 

but my php file will be huge. Sorry if this is confusing.

Thanks again

in_category can take an array, so you can do:


if(in_category(array( 9, 'blue-cheese', 'Stinky Cheeses' ))){
   echo "You must like cheese!";
}

this says if the category is id= 9 OR slug = blue-cheese OR name = Stinky Cheese, then the line, you must like cheese! will be printed on the screen. You could do something like that and have multiple if statements.

Thank You.

Hello

Is it possible to do with current post.
because the given solution is with specific tag and category.
I want to show some posts from current category and current tag(or custom taxonomy) on single.php

Any help will be appreciated.

Yes, you can do this with a second loop. Although it would be better to create a specific page to do this on and not use single.php. Check this article out.

So you you have something like this

<?php $wp_query = new WP_Query('cat=10'); // use your category id
while($custom_query->have_posts()) : $custom_query->the_post(); ?>

	<div <?php post_class(); ?> id="post-<?php the_ID(); ?>">
		<h1><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h1>
		<?php the_content(); ?>
               <?php the_tags(); ?> // gets the tags
               <?php the_terms(); ?> //gets custom taxonomy, you need to specify which one you want.
	</div>

<?php endwhile; ?>
<?php wp_reset_postdata(); // reset the query ?>