Support » Fixing WordPress » Select categories based on page id

  • Hello guys,
    I am
    using b/m code for selecting category based on the page id:
    Can you please correct me whats wrong in this code as it not selecting the proper category in get_posts function.

    if(is_page(’53’))
    {$cat=5;}
    else
    {$cat=1;}
    $myposts = get_posts(‘numberposts=10&offset=0&category=$cat’);

Viewing 1 replies (of 1 total)
  • you can’t put a variable inside that string

    it should look like this

    $myposts = get_posts(array('numberposts' => '10', 'offset' => '0', 'category' => $cat))

Viewing 1 replies (of 1 total)
  • The topic ‘Select categories based on page id’ is closed to new replies.