WordPress.org

Forums

Getting first post id from category (1 post)

  1. michellekoen
    Member
    Posted 4 years ago #

    I've written a small bit of code for my husband's record label website powered with wp. He recently upgraded to 3.1 (can't tell me which version he was running before but I suspect 3.0.4) and the code has stopped working. For the life of me I cannot figure out why.

    if (is_category()) {
    
     global $post, $cat;
    $category = get_the_category();
    $mycat = $category[1]->cat_ID;
    if ($category[1]->cat_ID='68'){
    $mycat = $category[0]->cat_ID;
    }
    
     $myposts = get_posts('numberposts=1&category=$mycat');
     foreach($myposts as $post) :
    
    $srcpost= get_the_ID();

    it goes on to use the $srcpost to call some info from the first post in the current category.
    However, since the upgrade it no longer calls from the post in the current category and is instead just setting $srcpost to the most recent post id in any category.

    Can someone help me get this first post in the current category.

    Cheers

Topic Closed

This topic has been closed to new replies.

About this Topic