wp_update_nav_menu also triggers post_updated

I have built a little script that indicates if one specific element should be taken from a cache instead of a query.

I started with an action triggered after each post update like this:

function post_cache($post_ID)
{
my_other_function($post_ID);
}
add_action(‘post_updated’,’post_cache’,10,1);

function my_other_function($variable)
{
echo $variable;
]

Each time a post is updated the my_other_function is triggered correctly and works as expected. Now if I add the same for menu updates, it does not only fire for menu updates but it also fires for every existing page.

function menu_cache($any_variable)
{
my_other_function($any_variable);
}
add_action(‘wp_update_nav_menu’,10,1);

When I save the menu, this function is fired but post_cache is also fired for all posts available. I don’t understand why it happens because there is no link between menu_cache and post_cache.

I have done the same for comments update and it also works as expected. It’s only when I use wp_update_nav_menu that post_cache is also called.

Thanks
Laurent

Read more here:: wp_update_nav_menu also triggers post_updated

Leave a Reply

Your email address will not be published. Required fields are marked *