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.

I have this filter:

function wpa_filter_nav_menu_objects( $items){
    global $count4footer;

    foreach( $items as $item ){

        $count = countPosts($item->ID);
        if($count!==false){
            $item->title = $item->title." ($count)";
            $count4footer[$item->ID]=$count;
        }
    }

    return $items;
}
add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects' );

I need to pass variable to the footer, but is printing null, I added global $count4footer; to the function , but to no effect.
How can I access this value later?

share|improve this question
    
You need global $count4footer; at the top of footer.php too. –  TheDeadMedic Jul 9 '13 at 11:07
add comment

1 Answer

Try to define $count4footer outside the function wpa_filter_nav_menu_objects.

$count4footer = array( );

function wpa_filter_nav_menu_objects( $items){
    global $count4footer;

    foreach( $items as $item ){

        $count = countPosts($item->ID);
        if($count!==false){
            $item->title = $item->title." ($count)";
            $count4footer[$item->ID]=$count;
        }
    }

    return $items;
}

add_filter( 'wp_nav_menu_objects', 'wpa_filter_nav_menu_objects' );
share|improve this answer
    
i tried is not working , thank you –  mIRU Jul 9 '13 at 10:44
add comment

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.