WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I've currently got this code on my homepage to display one random post from the Work section on my website - this is a custom post type utilising taxonomies - not blog posts:

<?php query_posts('post_type=work&posts_per_page=1&orderby=rand'); ?>

I want the items to be randomised so that a different one displays each time and I only want to display one item. However I want to know if it's possible to limit it to just one taxonomy rather than all 5 that I have set up. I'd like to just show the work items listed within 'Artists'

Is this possible?


I've tried:

<?php $query = new WP_Query( array( 'work' => 'artists', 'orderby' => 'rand', 'posts_per_page' => '1' ) ); ?>

but this doesn't work - it brings back a link top 'home' instead. Not sure what I'm doing wrong.

share|improve this question

closed as not a real question by toscho Jul 19 '12 at 23:26

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

Without knowing more details about your taxonomy schema, giving a precise answer will be difficult. However, query_posts() can be filtered by taxonomy, so you should easily be able to do what you need.

share|improve this answer
I've created a cutom post type called work and within this created 5 taxonomies - one of which is 'artists'. I would like to display 1 random artists taxonomy on the homepage for each visit. How would I adjust my code to do this as I've tried a few things from the link you've given and nothing works. – Evie Milo Oct 25 '11 at 15:32

Not the answer you're looking for? Browse other questions tagged or ask your own question.