0

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

  • 1
    At first you are missing the second mandatory argument for defining a function in your add_action() call. This may resolves the issue. Not sure… It should be add_action('wp_update_nav_menu', 'menu_cache');. Note: You can omit the 3rd and 4th parameter as 10 and 1 are the default values. – Fabian Marz Sep 18 '18 at 23:48
  • Hello Fabian, that actually solved the issue, thanks! – user3638239 Sep 22 '18 at 10:22
0

The solution was given by Fabian Marz. I remove the default parameters and added one variable in the function call.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.