Skip to content

Instantly share code, notes, and snippets.

@hayashikejinan
Last active August 29, 2015 14:26
Show Gist options
  • Select an option

  • Save hayashikejinan/fcfb7ba6e582b388ac96 to your computer and use it in GitHub Desktop.

Select an option

Save hayashikejinan/fcfb7ba6e582b388ac96 to your computer and use it in GitHub Desktop.
WordPress で次回予告 (一番近い未来の予約投稿タイトル、無ければ下書きの) を取得するおれおれ関数
<?php
/**
* @author hayashikejinan
* @copyright Copyright (c) 2015, hayashikejinan
* @link http://hayashikejinan.com/
* @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
* @return string|void
*/
function hogehoge_get_feature_post_title() {
$feature_posts_args = array(
'posts_per_page' => 1,
'category' => '',
'category_name' => '',
'orderby' => 'date',
'order' => 'ASC',
'include' => '',
'exclude' => '',
'meta_key' => '',
'meta_value' => '',
'post_type' => 'post',
'post_status' => 'future',
);
$feature_posts = get_posts( $feature_posts_args );
if ( empty( $feature_posts ) ) {
$feature_posts_args['post_status'] = 'draft';
$draft_posts_args = $feature_posts_args;
$draft_posts = get_posts( $draft_posts_args );
$feature_posts = $draft_posts;
}
return reset( $feature_posts )->post_title ? esc_attr( reset( $feature_posts )->post_title ) : '';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment