• Resolved robdnc

    (@robdnc)


    Hi, Confused from Manchester here.

    I’ve got a bit of code :

    //$cat=get_query_var(‘cat’);
    //echo($cat); — just to check that the category ID is coming through – it is
    //$posts = get_posts(‘numberposts=3&offset=0&cat=$cat’);

    But it’s not using the variably within the category, it’s just pulling through all posts. Any ideas? Thanks

Viewing 4 replies - 1 through 4 (of 4 total)
  • The code you’ve posted is commented out, ie. it doesn’t run.. (though it’s not clear if you posted it like that intentionally)..

    Example:

    <?php
    
    $somevar = 1;
    //$anothervar = 2;
    
    ?>

    $somevar has a value of 1, however $anothervar never gets set because of the two forward slashes at the start of the line which comment out the code(stop it from being executed).

    Please clarify if the slashes were intentional, if not, that’s the problem.. 😉

    Thread Starter robdnc

    (@robdnc)

    Yes sorry, was intentional. When posting code it says ‘put between backticks’ though I wasn’t clear what those are. ANYWAY.

    Problem solved I think. If I change from:

    $posts = get_posts('numberposts=3&offset=0&cat=$cat');

    to

    $posts = get_posts("numberposts=3&offset=0&cat=$cat");

    Then it works fine. Which is odd, because

    $posts = get_posts('numberposts=3&offset=0&cat=4');

    works perfectly. So there you go, cheers for looking anyway.

    Variables inside single quotes are treated literally, where as variables inside double quotes are interpreted(i should of caught that, hehe).. 😉

    Thread Starter robdnc

    (@robdnc)

    aaaaaaaaaah. Thanks!

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘Help with $cat not pulling through the variable’ is closed to new replies.