i want to add custom field to post automatically so i have this code on theme function.php
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, 'test', 'text . $slug . text', true);
}
all works but value of custom field is plain text:
text . $slug . text
i want to be TEXT + id or slug of post + TEXT
so that variable $slug is not working and script add it as plain text
fixed by changing this line to
add_post_meta($post_ID, 'test', "text '. $post_ID .' text", true);