WordPress.org

Ready to get started?Download WordPress

Forums

add_action('publish_post') only works with deactivation of Meta Box plugin (3 posts)

  1. Ahmed Hamouda
    Member
    Posted 1 year ago #

    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.

  2. bcworkz
    Member
    Posted 1 year ago #

    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.

  3. Ahmed Hamouda
    Member
    Posted 1 year ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic