The Support Forums will be in read-only mode for a scheduled maintenance window on 01 September 2016 14:00 UTC - 20:00 UTC. More information.

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

  1. Ahmed Hamouda
    Posted 3 years 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
    Posted 3 years 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
    Posted 3 years 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