予めACFなどで ‘post_views’ フィールド(数値フィールド)を作成しておく。
// ---------------------------------------- // 閲覧数用フィールド // singleページにアクセスしたとき、その投稿の'post_views'フィールドにプラス1する // ---------------------------------------- function update_custom_meta_views() { global $post; if ( is_single() ) { $id = get_the_ID(); $post_views = get_field('post_views', $id); $post_views++; update_field('post_views', $post_views, $id); } } add_action( 'wp_head', 'update_custom_meta_views' );