$ post_id와 get_the_ID ()의 차이점은 무엇입니까?


답변:


17

get_the_ID()반환 현재 게시물의 ID를 의 방법으로 get_post. Get post global$post 다르게 지정된 매개 변수를 전달하지 않으면 현재 post가 변수 인 것으로 가정합니다 . 즉 get_the_ID(),에 포함 된 것과 동일한 값을 반환해야합니다 $post->ID. Using를 get_the_ID()사용하면 간접적으로 전역을 다루더라도 전역을 직접 다루지 않아도됩니다. get_the_ID()테마 템플릿 파일에서 사용하면 오류가 덜 발생하는 경향이 있습니다.

$post_id는 게시물 ID를 참조하는 데 일반적으로 사용되는 변수 이름이지만 $post특정 컨텍스트에서 몇 번 정의되지만 핵심 변수는 아닙니다 .

grep -Rn '$ post_id'* | grep 글로벌
wp-admin / includes / class-wp-comments-list-table.php : 25 : 글로벌 $ post_id;
wp-admin / includes / class-wp-comments-list-table.php : 45 : 전역 $ post_id, $ comment_status, $ search, $ comment_type;
wp-admin / includes / class-wp-comments-list-table.php : 141 : 전역 $ post_id, $ comment_status, $ comment_type;
wp-admin / includes / class-wp-comments-list-table.php : 250 : 전역 $ post_id;
wp-admin / includes / ajax-actions.php : 691 : 글로벌 $ wp_list_table, $ post_id;
wp-includes / ms-deprecated.php : 115 : 함수 clear_global_post_cache ($ post_id) {
당사 사이트를 사용함과 동시에 당사의 쿠키 정책개인정보 보호정책을 읽고 이해하였음을 인정하는 것으로 간주합니다.
Licensed under cc by-sa 3.0 with attribution required.