0

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.

1
  • How do you know when it changes the date - and why does it need it need to change it before? What should be happening after the button is pressed? – Q Studio Dec 20 '20 at 14:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.