WordPress 現在の投稿が何番目かを取得する方法
WordPress 現在の投稿が何番目かを取得する方法
<?php $where = $wpdb->prepare( "WHERE p.post_date >= %s AND p.post_type = %s AND p.post_status = 'publish'", $post->post_date, $post->post_type ); $sql = "SELECT COUNT(*) FROM $wpdb->posts AS p $where ORDER BY p.post_date DESC"; $number = (int)$wpdb->get_var( $sql ); echo "<p>現在の投稿は $number 番です。</p>"; ?>