사용자 정의 필드를 자동 생성하는 플러그인이 있습니다. 아무도 내가 "게시"를 누르면 게시물에서 빈 사용자 정의 필드를 자동으로 제거하는 방법을 알고 있습니까?게시시 값이없는 사용자 정의 필드 자동 제거
수표 수표를 넣고 값이없는 경우 사용자 정의 필드를 제거하는 function.php에 넣을 수 있습니까?
사용자 정의 필드를 자동 생성하는 플러그인이 있습니다. 아무도 내가 "게시"를 누르면 게시물에서 빈 사용자 정의 필드를 자동으로 제거하는 방법을 알고 있습니까?게시시 값이없는 사용자 정의 필드 자동 제거
수표 수표를 넣고 값이없는 경우 사용자 정의 필드를 제거하는 function.php에 넣을 수 있습니까?
wp_insert_post_data은 관리 패널에서 데이터베이스 쓰기 전에 발생하는 훅입니다. 이 함수를 사용하여 데이터를 검사하는 함수를 호출 한 다음 빈 사용자 정의 필드 항목을 제거 할 수 있습니다.
또는 프런트 엔드에 the_content 후크를 사용하여 빈 사용자 정의 필드가 사용자에게 표시되기 전에 제거 할 수 있습니다.
또는 테마 파일을 제어 할 수있는 경우 사용자 정의 필드의 데이터를 테스트하기 만하면됩니다.
add_action('save_post','my_cf_check');
function my_cf_check($post_id) {
// verify this is not an auto save routine.
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return;
//authentication checks
if (!current_user_can('edit_post', $post_id)) return;
//obtain custom field meta for this post
$custom_fields = get_post_custom($post_id);
if(!$custom_fields) return;
foreach($custom_fields as $key=>$custom_field):
//$custom_field is an array of values associated with $key - even if there is only one value.
//Filter to remove empty values.
//Be warned this will remove anything that casts as false, e.g. 0 or false
//- if you don't want this, specify a callback.
//See php documentation on array_filter
$values = array_filter($custom_field);
//After removing 'empty' fields, is array empty?
if(empty($values)):
delete_post_meta($post_id,$key); //Remove post's custom field
endif;
endforeach;
return;
}
: 여기