2013-08-05 21 views
0

自動添加自定義字段,我發現一些代碼來自動添加自定義字段到每一個新崗位:與分類URL

add_action('publish_page', 'add_custom_field_automatically'); 
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, 'cat', '' . get_category_link($category->term_id) . '', true); 
    } 
} 

我已經把這個代碼放到我的functions.php文件,並將其一半的工作。它會自動添加一個新的自定義字段,但是如何回顯作爲posts類別slug的值?

由於自定義表格只會在發佈後添加,因此我們已經爲其選擇了一個類別。那麼我們可以迴應這個嗎?

add_action('publish_page', 'add_custom_field_automatically'); 
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, 'cat', 'CATEGORY LINK HERE', true); 
    } 
} 

回答

0

你需要的帖子ID:

echo get_post_meta($post_ID, 'cat', true); 

我很好奇,你在哪裏試圖呼應呢?