php - Filter wordpress-menu by category name -



php - Filter wordpress-menu by category name -

i need filter wordpress-menu category name.

what found far next loop, gives me menu-items:

function exclude_menu_items( $items, $menu, $args ) { // iterate on items search , destroy foreach ( $items $key => $item ) { //if ( $item->object_id == 168 ) unset( $items[$key] ); print_r($item); echo '<br>'; //var_dump(get_the_category($item->id)); //echo get_query_var('cat'); } homecoming $items; } add_filter( 'wp_get_nav_menu_items', 'exclude_menu_items', null, 3 );

i added capability pages have categories this:

function add_categories_for_pages() { register_taxonomy_for_object_type('category', 'page'); } add_action( 'init', 'add_categories_for_pages' );

but how can pages category menu item?

seems have found solution, don't know if it's best far seems work:

function exclude_menu_items( $items, $menu, $args ) { // iterate on items search , destroy foreach ( $items $key => $item ) { $categories = get_the_category( $item->object_id ); foreach($categories $category){ if($category->cat_name != 'mycatname'){ unset( $items[$key] ); } } } homecoming $items; }

what think?

php wordpress add-filter

Comments

Popular posts from this blog

java - How to set log4j.defaultInitOverride property to false in jboss server 6 -

c - GStreamer 1.0 1.4.5 RTSP Example Server sends 503 Service unavailable -

Using ajax with sonata admin list view pagination -