Support » Plugins » Hacks » add_action('publish_post') only works with deactivation of Meta Box plugin

  • My code in functions.php is

    add_action('publish_page', 'add_custom_field_automatically');
    	add_action('publish_post', 'add_custom_field_automatically');
    	function add_custom_field_automatically($post_ID) {
    		global $wpdb;
    		if(!wp_is_post_revision($post_ID)) {
    			add_post_meta($post_ID, 'status', 'notanswered', true);
    		}
    	}

    It only works if I deactivated Meta Box plugin

    I wonder why? Thanks in advance.

Viewing 2 replies - 1 through 2 (of 2 total)
  • Moderator bcworkz

    (@bcworkz)

    Just guessing, could be a name collision. Try renaming your function or meta key names. Try to use unusual elements in your naming, such as your initials. Could be an issue on the action callback stack, try adding your action with either a lower or higher priority.

    Probably just a pasting error, but you don’t need to call add_action() twice for the same thing.

    Thread Starter Ahmed Hamouda

    (@ahmedhamouda)

    The purpose of the code is to have a default value for the metabox that’s why I have to use the same name collision. Any ideas?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘add_action('publish_post') only works with deactivation of Meta Box plugin’ is closed to new replies.