• hey there

    so a function was created to allow a site to serve doubleclick adverts based on the category that it’s showing. and everything works great except for the search results page that it loses scope and returns an id based on the latest post’s category

    else if ( is_search()) {
    		$zoneID = "search";

    my function looks like such :

    function getCategory() {
    	if (count($post->ancestors)) {
    		$parentPage = array_pop($post->ancestors);
    	} else if (is_array($posts)) {
    		if ($posts[0]->post_parent == 0) {
    			$parentPage = $posts[0]->ID;
    		} else $parentPage = $posts[0]->post_parent;
    	}
    	$category = get_the_category($parentPage);
    	$categoryID = $category[0]->term_id;
    	if (is_home()) {
    		$categoryID = 0;
    	}
    	return $categoryID;
    }

    Any ideas ?

  • The topic ‘Is_search losing scope’ is closed to new replies.