get_the_modified_author()


WordPressのget_the_modified_author()関数は、指定された投稿またはページを最後に更新したユーザーの表示名を取得するために使用されます。

構文

get_the_modified_author();
  • string — 投稿を最後に更新したユーザーの表示名を返します。

例1: 最終更新者の表示

この例では、投稿を最後に更新したユーザーの名前を表示します。

<?php echo get_the_modified_author(); ?>

例2: 条件付きで最終更新者を表示

投稿が更新されている場合にのみ、最終更新者の名前を表示します。

<?php if (get_the_modified_author()) { echo '最終更新者: ' . get_the_modified_author(); } ?>

例3: カスタム投稿タイプでの使用

カスタム投稿タイプで最終更新者の名前を取得します。

<?php $post_id = get_the_ID(); echo get_the_modified_author($post_id); ?>

例4: 著者情報と一緒に表示

投稿の著者と最終更新者の両方を表示します。

<?php echo '著者: ' . get_the_author() . ' | 最終更新者: ' . get_the_modified_author(); ?>

例5: 特定の投稿IDでの使用

特定の投稿IDを使用して最終更新者の名前を取得します。

<?php echo get_the_modified_author(123); ?>

例6: ループ内での使用

ループ内で各投稿の最終更新者を表示します。

<?php while (have_posts()) : the_post(); echo get_the_modified_author(); endwhile; ?>

例7: ショートコード内での使用

ショートコード内で最終更新者の名前を表示します。

function modified_author_shortcode() { return get_the_modified_author(); }
add_shortcode('modified_author', 'modified_author_shortcode');

例8: カスタムフィールドとの組み合わせ

カスタムフィールドと一緒に最終更新者の名前を表示します。

<?php echo '最終更新者: ' . get_the_modified_author() . ' | カスタムフィールド: ' . get_post_meta(get_the_ID(), 'custom_field', true); ?>

注意点:

  • この関数は、投稿が更新されていない場合には空の文字列を返すことがあります。
  • 投稿IDを指定しない場合、現在のループ内の投稿が対象となります。

関連機能: