2013-08-05 6 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 파일에이 코드를 넣어 가지고, 그것은 중간 작동합니다. 새 사용자 정의 필드를 자동 추가하지만, 게시물 카테고리 슬러그가되는 값을 어떻게 반영합니까?

맞춤 양식은 게시 된 후에 만 ​​추가되므로 이미 카테고리를 선택했을 것입니다. 그래서 우리는 이것을 반향시킬 수 있습니까?

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); 

내가 궁금을, 어디이 에코하려고?

관련 문제