Custom field in PHP file

时间:2019-11-05 作者:Justifield

我是PHP的初学者,所以我希望有人能帮助我解决这个问题。

我想用以下插件显示帖子的过期日期https://wordpress.org/plugins/advanced-schedule-posts/

我认为我可以使用:$hasp_expire_date = get_post_meta( $post_id, ‘hasp_expire_date’, true );

但我不知道如何将其插入到php文件中。我需要在此代码中放置(此处显示代码):

                $num_comments = get_comments_number( $block_data[\'id\'] );
                $entry_comments = \'CODE HERE<i class="fa fa-speech-bubble"></i><span>\'.$num_comments.\' \'._nx( \'Comment\', \'Comments\', $num_comments, \'comments\', \'uncode\' ).\'</span>\';

1 个回复
SO网友:ChristopherJones

假设您的$hasp_expire_date = get_post_meta( $post_id, ‘hasp_expire_date’, true ); 为您提供所需的正确值,您将其存储在$hasp_expire_date 变量

因此,将第二行编辑为:

$num_comments = get_comments_number( $block_data[\'id\'] );

// Pull in the value you need
$hasp_expire_date = get_post_meta( $post_id, ‘hasp_expire_date’, true );

// You are going to concatenate or add that value to your string.
$entry_comments = $hasp_expire_date.\'<i class="fa fa-speech-bubble"></i><span>\'.$num_comments.\' \'._nx( \'Comment\', \'Comments\', $num_comments, \'comments\', \'uncode\' ).\'</span>\';

希望有帮助!!