Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Hello, Herve and Linda

    I have the same problem. At my website Clickomania, posts of the day used to show up with a delay of one day (February 24 would show the posts of the twenty-third).

    The problem seems to be a combination of different time zones and wordpress cache (strtotime and current_time). If the server and wordpress have different settings, then, midnight is not determined correctly.

    I tried to fix that with the following code in the class-query.php file. It works for me, but since I am wordpress/PHP dummy, I would feel much better if you took a look at it.

    /**
     * Get the number of seconds left in the day.
     *
     * @return int $seconds Number of seconds left until midnight.
     */
    public static function get_seconds_left_in_day(): int {
        $now      = new DateTime( 'now', wp_timezone() );
        $midnight = new DateTime( 'tomorrow', wp_timezone() );
    
        // Seconds left until midnight.
        $seconds_remaining = $midnight->getTimestamp() - $now->getTimestamp();
    
        if ( 0 >= $seconds_remaining || 86400 < $seconds_remaining ) {
            $seconds_remaining = DAY_IN_SECONDS; // Default: a full day, i.e. 86400 seconds.
        }
    
        /**
         * Allow filtering the time the data is cached.
         *
         * @param int $seconds_remaining Number of seconds.
         */
        return (int) apply_filters( 'jeherve_posts_on_this_day_cache_duration', $seconds_remaining );
    }

    And:

    $current_date = ( new DateTime( 'now', wp_timezone() ) )->format( 'Ymd' );
    
            $transient_key = sprintf(
                'jeherve_posts_on_this_day_%1$d_%2$d_%3$s_%4$s_%5$s',
                $max,
                $back,
                esc_attr( $types ),
                ( true === $exact_match ? 'exact' : 'aweek' ),
                $current_date
            );

    Thanks! And thanks again for the great plugin!

    • This reply was modified 3 months, 2 weeks ago by mrclicko.

    I have exact the same problem with version 2.4.1. ChatGPT says, that the API key has not been used.

    • This reply was modified 11 months, 3 weeks ago by mrclicko.
    Thread Starter mrclicko

    (@mrclicko)

    Thanks a lot!

    Thread Starter mrclicko

    (@mrclicko)

    Perfect! Thank you a lot!

Viewing 4 replies - 1 through 4 (of 4 total)