首先,我尝试获取post\\u元数据,最近,我尝试获取get_post_field()
内部atransition_post_status
挂钩函数,如:
<?php
add_action( \'transition_post_status\', \'yes_send_email_notification\', 10, 3 );
function yes_send_email_notification( $new_status, $old_status, $post ) {
if( \'mycpt\' === $post->post_type && \'new\' === $old_status && \'pending\' === $new_status ) :
$post_id = $post->ID;
/**
* Generate Dynamic values
*/
$post_view_link = get_permalink( $post_id );
$message = "My custom message<br>";
$message .= "Link: ". esc_url( $post_view_link );
//headers are duely passed
//$headers = ...
wp_mail( \'[email protected]\', \'New MyCPT submitted\', $message, $headers );
endif;
}
电子邮件工作正常。现在我试着包括
post_content
,
post_title
(如果可能,
post_meta
数据),但不幸的是,我无法获取任何内容。
$post_id = $post->ID;
$post_view_link = get_permalink( $post_id );
$post_title = get_post_field( \'post_title\', $post, \'display\' );
$post_content = get_post_field( \'post_content\', $post, \'display\' );
$post_excerpt = wp_trim_words( $post_content, 70, null );
但我失败了。
$post_title
和
$post_excerpt
没有得到填充。(同样的情况也发生在
post_meta
字段)
我怎样才能post_fields
(如果可能的话post_meta
字段)内部transition_post_status
挂钩函数?