sourcecode

워드프레스 투고 수정 시간 변경 방법

codebag 2023. 2. 22. 21:52
반응형

워드프레스 투고 수정 시간 변경 방법

post_meta를 원하는 대로 업데이트 할 수 있습니다.단, 게시물의 modified_time은 변경되지 않습니다.

get_modified_time에 의존하여 게시물이 마지막으로 갱신된 시간을 사용자에게 표시합니다.(신규일수록 좋습니다)

여기저기 찾아봤는데 아직 이 기술을 쓰는 사람이 없네요.

답을 아는 사람?

감사합니다!

이를 위해 wpdb::query()를 사용했습니다.

global $wpdb;

//eg. time one year ago..
$time = time() - DAY_IN_SECONDS * 365;

$mysql_time_format= "Y-m-d H:i:s";

$post_modified = gmdate( $mysql_time_format, $time );

$post_modified_gmt = gmdate( $mysql_time_format, ( $time + get_option( 'gmt_offset' ) * HOUR_IN_SECONDS )  );

$post_id = /*the post id*/;

$wpdb->query("UPDATE $wpdb->posts SET post_modified = '{$post_modified}', post_modified_gmt = '{$post_modified_gmt}'  WHERE ID = {$post_id}" );

주의: 사용할 수 없습니다.wp_update_post()post_insert_post호출하여 post_post_post 변수를 현재 날짜로 설정하기 때문에 post_insert_post에 대해 설명을 원하는 경우 post_insert_post 변수를 현재 날짜로 설정합니다.

PHP에서는 매우 간단합니다.80는, 투고 번호입니다.

// update post_modified and post_modified_gmt `datetime` on a post
$update = array( 'ID' => 80 );
wp_update_post( $update );

게시물 세트를 변경하려면 Query Loop을 사용하여 각 게시물 ID를 가져오는 것이 좋습니다.

이전에 Ajax 요청에서 게시 ID를 수집했다고 가정하면 업데이트 할 수 있습니다.post_modified그리고.post_modified_gmt통상의 사용wp_update_post기능:

$date = current_time('mysql');
                        
wp_update_post(array(
                            
        'ID'                => $post_id,
        'post_modified'     => $date,
        'post_modified_gmt' => get_gmt_from_date($date),
));

자원.

https://developer.wordpress.org/reference/functions/wp_update_post/

언급URL : https://stackoverflow.com/questions/17412202/how-to-change-the-modified-time-of-a-wordpress-post

반응형