WordPressで最新記事の投稿URLを取得する方法
WordPressで投稿タイプ別に最新記事を取得するスクリプトを書いたので備忘録で残しておきます。 functions.phpに登録する方法
1 2 3 4 5 6 7 8 9 10 11 |
<?php function get_last_article_id($post_type) { $args = array( 'posts_per_page' => 1, // 1記事 'orderby' => 'date', //日付順 'order' => 'DESC', // 最新順 'post_type' => $post_type, // パラメータで取得したpost_type ); $my_posts = get_posts( $args ); wp_reset_postdata(); return $my_posts[0]->ID; } |
wp_res…