• Resolved sumeetjain

    (@sumeetjain)


    I’d like my front page to show posts only from the category which was most recently created. I’ve checked the Codex for information on this, and the posts query function comes close, but I can’t think of how to manipulate it to work for me.

    Can anyone assist? I would really appreciate it.

    Thanks for your time,
    Sumeet

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hmm. Interesting request. This may do:

    <?php
    global $wpdb;
    $newcat = $wpdb->get_var("SELECT cat_ID FROM $wpdb->categories WHERE category_count > 0 ORDER BY cat_ID DESC LIMIT 1");

    query_posts("cat=$newcat");
    ?>

    So long as nothing unusual is going on in your database and categories are being numbered sequentially, the query should work as one would expect.

    Thread Starter sumeetjain

    (@sumeetjain)

    Worked like a charm. Thanks so much for your help.

    Just thought I’d update this – since I needed (almost) the same thing. My WP version is 2.3, and the following works (since the wp-categories table is no longer in existence with 2.3…)

    <?php
        global $wpdb;
        $newcat = $wpdb->get_var("SELECT term_id FROM $wpdb->terms WHERE term_id > 0 ORDER BY term_id DESC LIMIT 1");
        query_posts("cat=$newcat");
    ?>
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Display Posts From Newest Category Only’ is closed to new replies.