重複したタイトルがサイト内にあって中身が違う場合、その同名のタイトルの中から最新の(IDが一番大きな)投稿を出す。
get_page_by_title(); やpost_exists(); だとどうしても重複したデータの古い(IDの小さい)投稿しか持って来られなかったので、
[code]array( [ ‘ID’ ] => [ ‘title’ ] )[/code]
の組み合わせで配列作って、array_unique();して取りだしてみた。他に方法ってあるのかなぁ…。
IDとtitleの組み合わせが取れてるので、データ引いてこれる。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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 );
View the code on Gist .