こんばんは、プログラム初心者です。
WordPressを使い、サイトを作成しています。
お知らせというコンテンツを作成し、
投稿時に新着通知メールが飛ぶ仕様です。
$postなどでタイトルと本文を取得しようとしても
何故かタイトルしか取得できず
カスタム投稿タイプが原因だとわかりました。
global $post; $my_posts= get_posts(array( 'post_type' => array('post','top_info'), 'numberposts' => 1 ));
など、調べて分かる限りのコードは試しましたが
やはりタイトルだけは取得できて、本文が取得できません。
新規投稿時の条件
if ( 'publish' == $new_status && 'publish' != $old_status && 'top_info' == $post->post_type )
カスタム投稿タイプのスラッグ名: 'top_info' 本文入力エリアフィールド名: 'info_text' 本文が格納されてるDBテーブル名: hs_postmeta 本文が格納されてるDBカラム名: postmeta_value
以上が情報です。
アドバイスをお願いします。
【追記】
function publishSentMail ( $new_status, $old_status, $post ) { if ( 'publish' == $new_status && 'publish' != $old_status && 'top_info' == $post->post_type ) { global $post; $args = array ( 'post_status' => array('publish') ); $the_query = new WP_Query($args); if ($the_query->have_posts()) { $the_query->the_post(); $key = get_post_custom_keys($post_id); $id = get_the_ID(); $meta_values = get_post_meta($id, $key); } mb_language("ja"); mb_internal_encoding("UTF-8"); $to = "*****@***.co.jp"; $subject = "タイトル"; $text = "$meta_values"; $from = "****"; $from_mail = "*************@****.co.jp"; $from_name = "****"; $header = ''; $header .= "Content-Type: text/plain \r\n"; $header .= "Return-Path: " . $from_mail . " \r\n"; $header .= "From: " . $from ." \r\n"; $header .= "Sender: " . $from ." \r\n"; $header .= "Reply-To: " . $from_mail . " \r\n"; $header .= "Organization: " . $from_name . " \r\n"; $header .= "X-Sender: " . $from_mail . " \r\n"; $header .= "X-Priority: 3 \r\n"; $response = mb_send_mail( $to, $subject, $text, $header); wp_reset_postdata(); } }
あなたの回答
tips
プレビュー