wordpressループ内外の変数

前提

functions.php のループ内でループ外の変数を使いたい。

ループ外で定義している1行目【$slug = $post->post_name;】の変数$slugを
ループ内【foreach ( $posts as $post ) {】 で使いたいんですが、中身空っぽくて・・・。
以下のソースの書き方が悪いんでしょうか・・・?

ご教示いただけると幸いです。

該当のソースコード

PHP

1 $slug = $post->post_name;2 3 $args = array(4 'post_type' => 'event',5 'post_status' => 'news',6 );7 8 $posts = get_posts( $args );9 10 foreach ( $posts as $post ) {11 $post_data = get_post();12 $multiple_recipients = array(13 '***@abc.com'14 );15 $subj = '検証';16 $body = '$slugは'.$slug.'<br>'.'$post_data->post_name'.$post_data->post_name;17 wp_mail( $multiple_recipients, $subj, $body );18 }

コメントを投稿

0 コメント