Is there any hook which is fired only when the post is "published" for the first time.
I dont want to execute my code when the post is "updated" or when its status is set to "not-published" and then "published" again.
EDIT:
add_action('draft_to_published','func_tion');
function func_tion($post){
$post_id = $post->ID;
if ( !get_post_meta( $post_id, 'mycoderan', $single = true ) )
// run code to manipulate data
wp_enqueue_script('plugin_name',plugin_dir_url(__FILE__ ).'script.js');
$params = array() // set parameters
wp_localize_script('plugin_name', 'params', $params );
update_post_meta( $post_id, 'mycoderan', true );
}
if
statement inside{ ... }
braces. w3schools.com/php/php_if_else.aspdraft_to_published
action seem to be triggered every time a post is published from draft multiple times. Are you relying on post meta to check if a post is published for the 1st time. Is there any native WP function that can be used instead?