Add_action increment value by 2 instead of 1
I am making a counter where I can count amount of posts ever posted on my blog and save the value in a option.
I have created a function that gets executed every time I publish new post, but the issue I see is that the counter value increases by 2 even though I only publish 1 post which I only want it to increase by one.
Here is the function gets executed every time I publish a post
function post_type_counter0() {
$number0 = get_option( 'wp_count_po0' );
$number0++;
update_option( 'wp_count_po0', $number0 );
}
And the function is hooked to the action
add_action( 'publish_post', 'post_type_counter0' );
I also tried to specify the value to be added to $number0 variable by doing this way
$number + 1;
But it still increased the value by 2 instead of 1.
Any idea??
Leave an answer