Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

So I'm trying to use a session to move a variable through pages. For some reason I literally cannot access anything from index.php to archive. I declare my session at the very top of my header.php like:

<?php
    if(!isset($_SESSION))
    {
        $_SESSION['catID'] = 3;
    }
?>

Then I move to the archive.php which pulls in the header via <?php get_header() ?> and my session is suddenly gone. I try to echo it out and get nothing. Same thing happens with normal variables - like it's out of scope.

Anybody else have a similar problem or a solution?

share|improve this question

1 Answer 1

up vote 1 down vote accepted

In WordPress you need to start the session with

if ( !session_id() ) { session_start(); }

in order to use session variables. You can enter this code into wp-config

See http://www.frank-verhoeven.com/using-session-in-wordpress

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.