New answers tagged

0

Ultimately the solution that I found was to use global $post; to retrieve the current post's ID. Immediately after wp_insert_post( $new_cpta ); above, I added global $post; $currentid = $post->ID; Then I was able to update the post meta for the correct post with $currentid in place of $post_id.


0

I have found a solution . If someone click a on "Edit" link or change anything of the post . A new meta field which meta key is "_edit_lock" is added . Thus we can do something when "Edit" link is clicked by add_action( 'added_post_meta', 'add_custom_field_automatically', 10, 4 ); add_action( 'updated_post_meta', 'add_custom_field_automatically', 10, 4 ); ...


2

Note! This code was not tested! <?php function my_visitor_cookie($post_id) { if ( empty($post_id) ) { global $post; $post_id = $post->ID; } // get post meta $count = get_post_meta($post_id, 'unique_post_visits', true); // if there was no meta value if( empty($count) ) { $count = 0; } // ...



Top 50 recent answers are included