• Hi-

    I am building a WordPress site that has two separate sections, one for employers and one for job candidates. The site needed two searches, since I only want a search to run on the pages in the corresponding half of the site. I figured out how to do that with the helpful info here: https://return-true.com/2010/10/using-multiple-search-forms-in-wordpress/comment-page-1/#comment-243232.

    On the search results pages, I need to display content according to which half of the site it’s on. For instance, there is a tab on the top of the page that says Employers or Job Candidates as appropriate. I need to test for whether it is an employer or candidate search results page in both header.php and footer.php, for different content.

    I found this code that successfully runs the test:

    $searchtype = '';
    if (is_search()){
        if(isset($_GET['search-type'])) {
            $searchtype = $_GET['search-type'];
        }
    }

    So here’s what I find confusing. I need to run this test in both header.php and footer.php. I would have thought the value was assigned to the variable in header.php, it would persist into footer.php, but that doesn’t seem to be the case. Are variable values cleared at the end of any file?

    It’s not a big deal but I’m curious and would rather not run extra code if I don’t need to.

    Thanks,
    Kim

Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
  • The topic ‘Do variable values persist?’ is closed to new replies.