Skip to content

Instantly share code, notes, and snippets.

@marushu
Last active August 29, 2015 14:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marushu/8938754cb54041b75fb1 to your computer and use it in GitHub Desktop.
Save marushu/8938754cb54041b75fb1 to your computer and use it in GitHub Desktop.
投稿を抽出する際、タイトルが同じ投稿がある場合、同名の投稿の中でIDが一番新しいもののみを出す
<?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 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment