• Hey, I’ve been trying to do it all night long searched a lot but couldn’t found a way. Well i’ve a select box that show categories of posts and when user select any value it shows post related to that category when select box value changes.

    <li id=”categories”><h2><?php _e( ‘Posts by Category’ ); ?></h2>
    <?php wp_dropdown_categories( ‘show_option_none=Select category’ ); ?>
    <script type=”text/javascript”>
    <!–
    var dropdown = document.getElementById(“cat”);
    function onCatChange() {
    if ( dropdown.options[dropdown.selectedIndex].value > 0 ) {
    location.href = “<?php echo esc_url( home_url( ‘/’ ) ); ?>?cat=”+dropdown.options[dropdown.selectedIndex].value;

    }

    }
    dropdown.onchange = onCatChange;
    –>
    </script>

    what i want is that when the page loads it show a random post from one category which i’ve achieved

    <?php query_posts(“cat=1”); ?>
    <?php query_posts( ‘orderby=rand&posts_per_page=1’ ); ?>

    But the problem is that it show the random post also when i change the value of select box. What i want is that when page load it shows 1 random post from 1 category but on the same page when user changes or selects a category from select box it should show all post from that selected category.

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Multiple queries on one page ?’ is closed to new replies.