Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

----EDIT------------

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.

1 Answer 1

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.