Skip to main content
added 70 characters in body
Source Link

If you're having an issue where the publish_post hook is being triggered twice you can try using a global variable to keep track of whether the hook has already been triggered.

// Declare a global variable global $publish_post_hook_triggered; $publish_post_hook_triggered = false;

add_action('publish_post', 'my_publish_post_function');

function my_publish_post_function($post_id) { // Check if the hook has already been triggered global $publish_post_hook_triggered; if ($publish_post_hook_triggered) { return; } // Set the global variable to indicate that the hook has been triggered $publish_post_hook_triggered = true;

// Declare a global variable
global $publish_post_hook_triggered;
$publish_post_hook_triggered = false;

add_action('publish_post', 'my_publish_post_function');

function my_publish_post_function($post_id) {
    // Check if the hook has already been triggered
    global $publish_post_hook_triggered;
    if ($publish_post_hook_triggered) {
        return;
    }
    // Set the global variable to indicate that the hook has been triggered
    $publish_post_hook_triggered = true;

    // Your code to run when the hook is triggered
}

}

If you're having an issue where the publish_post hook is being triggered twice you can try using a global variable to keep track of whether the hook has already been triggered.

// Declare a global variable global $publish_post_hook_triggered; $publish_post_hook_triggered = false;

add_action('publish_post', 'my_publish_post_function');

function my_publish_post_function($post_id) { // Check if the hook has already been triggered global $publish_post_hook_triggered; if ($publish_post_hook_triggered) { return; } // Set the global variable to indicate that the hook has been triggered $publish_post_hook_triggered = true;

// Your code to run when the hook is triggered

}

If you're having an issue where the publish_post hook is being triggered twice you can try using a global variable to keep track of whether the hook has already been triggered.

// Declare a global variable
global $publish_post_hook_triggered;
$publish_post_hook_triggered = false;

add_action('publish_post', 'my_publish_post_function');

function my_publish_post_function($post_id) {
    // Check if the hook has already been triggered
    global $publish_post_hook_triggered;
    if ($publish_post_hook_triggered) {
        return;
    }
    // Set the global variable to indicate that the hook has been triggered
    $publish_post_hook_triggered = true;

    // Your code to run when the hook is triggered
}
Source Link

If you're having an issue where the publish_post hook is being triggered twice you can try using a global variable to keep track of whether the hook has already been triggered.

// Declare a global variable global $publish_post_hook_triggered; $publish_post_hook_triggered = false;

add_action('publish_post', 'my_publish_post_function');

function my_publish_post_function($post_id) { // Check if the hook has already been triggered global $publish_post_hook_triggered; if ($publish_post_hook_triggered) { return; } // Set the global variable to indicate that the hook has been triggered $publish_post_hook_triggered = true;

// Your code to run when the hook is triggered

}