WordPress.org

Ready to get started?Download WordPress

Forums

Select categories based on page id (2 posts)

  1. akhtarusman
    Member
    Posted 3 years ago #

    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');

  2. tbennett04
    Member
    Posted 3 years ago #

    you can't put a variable inside that string

    it should look like this

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

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.