• Hi,

    I have an integration where posts from that site saves as a post in wordpress, but I can’t seem to figure out how to get the ‘post_date’ to show the actual PublishDate.. It saves and are shown with the date ‘1970-01-01’, but if I print out $item->PublishDate I get the real date..
    Could someone please help me figure this out?

    function fetch_cision_news()
        {
            $params = array(
                'PageIndex' => 1,
                'PageSize' => 0,
                'detailLevel' => 'detail',
                'format' => 'json',
                'tags' => null,
                'startDate' => null,
                'endDate' => null,
            );
            $url = self::CISION_BLOCK_FEED_URL . self::CISION_SOURCE_UID . '?' . http_build_query($params);
            $response = wp_safe_remote_request($url, array(
                'headers' => array(
                    'User-Agent' => 'mbp/cision',
                ),
            ));
            $result = null;
            if (!is_wp_error($response) && ($response['response']['code'] == 200 || $response['response']['code'] == 201)) {
                $result = json_decode( $response['body'] );
                if ( isset( $result->Releases ) && is_array( $result->Releases ) ) {
                    foreach ( $result->Releases as $item ) {
                        $post_list = get_posts( array(
                            'cat' => self::WP_CATEGORY,
                            'meta_key' => 'cision_item_id',
                            'meta_value' => $item->EncryptedId,
                            'post_type' => 'post',
                        ) );
    
                        if (empty($post_list)) {
                            $postarr = array(
                                'comment_status' => 'closed',
                                'meta_input' => array(
                                    'cision_item_id' => $item->EncryptedId,
                                    'is_regulatory' => (int) $item->IsRegulatory,
                                ),
                                'ping_status' => 'closed',
                                'post_category' => array( self::WP_CATEGORY ),
                                'post_status' => 'publish',
                                'post_author' => 1,
                                'post_content' => $item->Body,
                                'post_date' => date( 'Y-m-d H:i:s', $item->PublishDate ),
                                'post_date_gmt' => date( 'Y-m-d H:i:s', $item->PublishDate ),
                                'post_title' => $item->Title,
                                'post_type' => 'post',
                                'posts_per_page' => 1,
                            );
                            wp_insert_post( $postarr, false );
                        }
                    }
                }
            }
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    If $item->PublishDate is a proper date string like “2020-03-25 12:34:56”, you don’t need the date() function. date() is expecting a valid timestamp, not a date string. If you need to convert another date format to the proper ‘Y-m-d H:i:s’ format, convert it to a timestamp with strtotime() and pass that return to date().

Viewing 1 replies (of 1 total)
  • The topic ‘Publishdate shows wrong date’ is closed to new replies.