【メモ】タイトルが同じ投稿がある場合、同名の投稿の中でIDが一番新しいもののみを出す

重複したタイトルがサイト内にあって中身が違う場合、その同名のタイトルの中から最新の(IDが一番大きな)投稿を出す。

get_page_by_title();post_exists(); だとどうしても重複したデータの古い(IDの小さい)投稿しか持って来られなかったので、

[code]array( [ ‘ID’ ] => [ ‘title’ ] )[/code]

の組み合わせで配列作って、array_unique();して取りだしてみた。他に方法ってあるのかなぁ…。
IDとtitleの組み合わせが取れてるので、データ引いてこれる。

<?php
$get_posts_arr = array();
$paged = ( get_query_var( 'paged' ) ) ? get_query_var( 'paged' ) : 1;
$args = array(
'post_type' => 'post',
'numberposts' => 10000,
'posts_per_page' => 100,
'paged' => $paged,
);
$another_way_retrieve_posts = get_posts( $args );
foreach( $another_way_retrieve_posts as $another_way_retrieve_post ) {
if( $another_way_retrieve_post ) {
$get_posts_arr[ "$another_way_retrieve_post->ID" ] = esc_html( strip_tags( $another_way_retrieve_post->post_title ) );
}
}
$get_posts_arr = array_unique( $get_posts_arr );