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' );
Related Posts:
- How to filter users on admin users page by custom meta field?
- Modify WordPress Rest Api Request/Response
- How to add some custom HTML into wordpress admin bar?
- Custom theme hooks / filters – passing arguments
- What params are available with the_content filter?
- How to hook wp_list_pages?
- Hook into admin post list page
- Add post/page ID to inserted links within the_content
- How to exclude/filter a tag from get_the_tag_list()
- Ajax, filters and shortcodes
- Filter the blog’s title without using global variables
- Multiple Ajax Data Action
- user_has_cap filter allows edit but will not allow save
- Add filter to wp_dropdown_pages() or wp_dropdown_categories() – no select container?
- Hook different functions to the same filter conditionally OR Pass additional arguments to existing filter?
- Changing a WordPress core function without hacking core
- How to remove get_post_metadata using remove_filter inside a class?
- where to apply “apply filters” and other Sanitization Functions
- Add guid filter to attachment in media library grid mode
- Pass parameter to the upload_dir filter
- Filter or Hook to catch pre-rendering of post content
- Sorting and limitation with pre_get_posts
- Warning: Missing argument 2 for widget_title filter
- check to see if hook is available
- Change term name only on front
- How do I hide the current page’s title?
- How to allow users to view pending posts of a specific custom post type?
- Remove filter callback: method in class
- Change name of existing post status type
- add_filter(‘the_content’, ‘…’) stops pagination from working
- How can I exclude tags from category_rss function?
- Header image automatically changes depending on season
- How to remove SKU’s from ALL products in Quick View – already remove from each product page
- How do I use remove_action on an add_action that uses an array?
- What is the downside of using a filter as a “poor man’s” dependency injection?
- Change the default 10-day expiration for the password protected pages cookie
- Add content as soon starts
- How can I change the language of automated Mails?
- How can I replace an oEmbed URL in post with actual embed HTML
- Replacing a deprecated filter ‘woocommerce_get_price’ with ‘woocommerce_product_get_price’
- How do you get specific tags from the_content?
- Add a filter inside an action init
- Is it possible to apply_filter on a wp_ajax_ action?
- Apply filters with multiple filters
- Filter by category and city for doctors and hospitals in wordpress
- Using add_filter to prepend content, result is out of order
- Why is overwriting $GLOBALS killing the_content()?
- Sorting products by price ( regular + sale price )
- get_posts() interrupt because of filter
- Create new custom field that calculates age
- Remove comments validation (remove filter?)
- How to query if meta_key does exist or not?
- Disable sanitize_file_name on upload without modifying functions.php
- Remove Site Name from wp_title WITHOUT removing from attribute
- Plugin default settings hook
- add_filter to the_content after apply_filters
- Best practice: Custom Post Type / Filter / Load more
- How to Edit Ecommerce filters URL, h1, h2 , Title
- Filter Media by attached page or blog post in Library
- How to stop DOMDocument destroying embeds?
- Redirect an archive page to its relevant URL-friendly filtered page
- How to modify image caption in posts?
- Extend Nonce Lifetime for Specific Nonce Creation
- Run `wp_insert_post_data` on all posts
- how to use substr with get_the_content()
- AJAX Post Filter
- Mystery line break
- Consult array data in REST API Filter
- WordPress add_filter to post_date
- How to add markup to the wp-custom-header div
- create a shortcode with acf including a filter
- Display post after choice two taxonomy terms
- How to stop echoing gallery inside content?
- Having issue with dynamic data within restrict_manage_posts function
- how to filter datalist table of wordpress
- Ajax Filtering Pagination
- Custom permalink for attachment
- Overriding Generated Attachment Post URL
- Pagination while keeping the filters
- Is there a function to edit Blogs contents in Blogs page?
- Filter on the day of the week from timestamp
- using filters on the function from class
- Put data in my-account/view-order/id/ page
- Can’t set properly WordPress add_filter function
- Hook inside a hook
- Filter WordPress Archive Widget to exclude posts with specific custom taxonomy term id
- Password protected Page add_filter to change the text doesn’t work
- How to filter content in Dashboard?
- How to remove a filter that is an anonymous object?
- add_filter not adding the filter
- Add class to all parent elements inside the_content
- Is this correct usage of filters in WordPress [closed]
- Date filter for post query not filtering results when variable outside the function
- Joining tables not working in the post editor page
- Getting entry ID from frm_email_message filter in formidable
- Auto append text after the title?
- Is there a hook or filter that adds a button to the left of the search box?
- Filter and manipulate the get_current_user() function
- add_filter(‘the_content’, ‘method’) does not trigger my custom method
- Limit total tags in the_content