Problem with executing a function on saving a post

The action save_post is also called during AJAX auto-save requests. But your value is not sent then, so you save an empty value for something that isn’t set. Start your save function with: if ( defined( ‘DOING_AUTOSAVE’ ) && DOING_AUTOSAVE ) return; See basic examples with more checks here and here.

What is the proper way implement a global $wp_rewrite?

It is not necessary to define $wp_rewrite in your function. The add_permastruct() and add_rewrite_rule() functions take care of that for you. Try removing the “global $wp_rewrite;” line and see if your code still works. The add_permastruct() function currently accepts three parameters. There is some backwards-compatibility logic in the function to correct for calls using the … Read more

Passing arguments in add_action inside search template

The footer doesn’t run in the global context, so the variable $map_vars is not in the correct scope. To keep the variable and the callback in the same scope, you could use a class: class Map_Var_Example { public static $map_vars; public static function map_data() { var_dump( self::$map_vars ); } } Map_Var_Example::$map_vars=”Test”; add_action( ‘wp_footer’, array( ‘Map_Var_Example’, … Read more