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 want to create a drop down list that will list all the posts in the category. I want the drop down list to appear on every post. So for example if I view a post that belongs to category Apples it should list all posts in category Apples

share|improve this question
up vote 2 down vote accepted

Hey @Ruriko ... its a 3 step action.

  1. get the current category ID
  2. get the posts for this specific category
  3. get the posts into a select menu

Please note that this code would use the first
category id altough you might assign several
categories to the same post. .

    $category = get_the_category(); 
    $catID = $category[0]->term_id;
    $args = array(
        'numberposts' => 5, 
        'category' => $catID            
    $catPosts = get_posts( $args );

    echo '<form method="POST">';
    echo '<select name="goToPost" onchange="document.location=this.value">';
    echo '<option value="">'.__('Relevent Posts', 'your_text_domain').'</option>';  
    foreach( $catPosts as $singlePost ) {
    echo '<option value="'.get_bloginfo('url').'/index.php?p='.$singlePost->ID.'">'.$singlePost->post_title.'</option>';
    echo '</select>';
    echo '</form>';

Hope this helps.
Cheers, Sagive.

share|improve this answer
It sort of works but when I select a post in the drop down list it doesn't go to that post. Is there a way to show all posts instead 5 only? since each category has different amounts of posts – Ruriko Oct 1 '12 at 11:03
aplogies... i left my testing code in there.. see my revised code - should work now (tested) – Sagive SEO Oct 1 '12 at 11:59

To show all posts, using WP Query with posts_per_page value equals to -1.

Not exactly the answer but here's an example of using wp query

More on WP Query here.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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