I change post date, but it updates only after refreshing the page
Question
Here’s my snippet:
function prideti_mygtuka($post){
echo'<div class="igno-button">';
echo '<form method="GET">';
echo '<input type="hidden" name="post-id" value=', esc_html(get_the_id()), '>';
echo '<button type="submit" class="btn btn-primary btn-sm btn-block">Iškelti į viršų</button>';
echo '</form>';
echo'</div>';
kai_paspaudzia_mygtuka();
}
function kai_paspaudzia_mygtuka(){
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
if (isset($_GET['post-id'])) {
$id = $_GET['post-id'];
$date = gauti_dabartine_data();
wp_update_post(array('ID' => $id,
'post_date' => $date,
'post_date_gmt' => get_gmt_from_date($date)));
}
}
}
function gauti_dabartine_data(){
date_default_timezone_set('Europe/Kiev');
$dabartine_data = date('Y-m-d G:i');
return $dabartine_data;
}
add_action('rtcl_listing_loop_extra_meta', 'prideti_mygtuka');
It should put a button on every post in the listings. When that button is pressed, it should update the date of that post to the current date and therefore, put the post on the top of the list.
The problem is it changes the date of the post only after pressing the button and refreshing the page. Can anyone point me in the right direction on how to fix this? Any help is appreciated.
0
2 years
2020-12-20T08:10:44-05:00
2020-12-20T08:10:44-05:00 0 Answers
7 views
0
Leave an answer