duanlan4801 2016-10-11 18:57
浏览 38

在function.php中通过php添加post id或slug

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

  • 写回答

1条回答 默认 最新

  • dpbz14739 2016-10-11 18:59
    关注

    fixed by changing this line to

            add_post_meta($post_ID, 'test', "text '. $post_ID .' text", true);
    
    评论

报告相同问题?