Skip to main content
deleted 8 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmtpost_date_gmt among blog_idblog_id, post_idpost_id, and post_gmt_tspost_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = $last_posts[0]; /*The most recent post object*/
$second_last_post = $last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = $last_posts[0]; /*The most recent post object*/
$second_last_post = $last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = $last_posts[0]; /*The most recent post object*/
$second_last_post = $last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;
added 2 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = last_posts[0];$last_posts[0]; /*The most recent post object*/
$second_last_post = last_posts[1];$last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = last_posts[0]; /*The most recent post object*/
$second_last_post = last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = $last_posts[0]; /*The most recent post object*/
$second_last_post = $last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;
added 47 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = last_posts[0]; /*The most recent post object*/
$second_last_post = last_posts[1]; /*The second most recent post object*/

If you still need to comparecompare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamptimestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = last_posts[0]; /*The most recent post object*/
$second_last_post = last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;

According to the codex, you're manipulating get_most_recent_post_of_user()'s returned value the wrong way. get_most_recent_post_of_user() directly returns the post_date_gmt among blog_id, post_id, and post_gmt_ts.

Anyway, if you want to get the 2 last posts of a specific author, use WP_Query instead, which should by default get last posts in the order you need.

$author_id = $author_id;

$args = array(
    'post_type'      => 'post',
    'author'         => $author_id,
    'posts_per_page' => 2,
);

$query      = new WP_Query( $args );
$last_posts = $query->get_posts(); /*Array of post objects*/

Now, you've got only the 2 last WP_Post objects accessible this way:

$last_post        = last_posts[0]; /*The most recent post object*/
$second_last_post = last_posts[1]; /*The second most recent post object*/

If you still need to compare the 2 last post's dates:

$last_post_date        = $last_post->post_date_gmt;
$second_last_post_date = $second_last_post->post_date_gmt;

Note that we now have 2 GMT string dates to deal with. For your comparaison, we'll convert them to timestamp:

$last_post_date        = strtotime( $last_post_date );
$second_last_post_date = strtotime( $second_last_post_date );

if ( ( $last_post_date - $post_date ) > 86400 )
    return;
added 13 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
added 699 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
added 21 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
[Edit removed during grace period]; added 5 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
added 8 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
added 7 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
deleted 11 characters in body
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading
Source Link
ClemC
  • 2k
  • 21
  • 26
Loading