0

情報の時間を比較するプラグインを作成しようとしています。WordPressデータベースで現在の時刻に。たとえば、投稿が5/6の12:00 pmに期限切れになった場合、その時間まで期限切れのタグは表示されません。

日付と時刻の式は、MM / DD / YYYY HH:MM(軍事時間)の形式です。これが私がこれまでにPHPコードに対して持っているものです。誰かが私のコードを調べて、私が何か間違ったことをしていないかどうかを確認できますか?お願いします?:)

global $post;
$expired_post = get_post_meta( $post->ID, 'deal_exp_dt', true);
$expired_post_time = strtotime($expired_post);

// CONTENT FILTER
add_filter( 'the_content', 'my_the_content_filter', 20 );
function my_the_content_filter( $content ) {
if(time() > $expired_post_time && !empty($expired_post)) {
    $content = sprintf(
        '<div id="expired_deal_post"><strong><span style="font-size: x-large;">EXPIRED</span></strong><br><span style="font-size: medium;">This deal has ended.</span></div>%s',
        $content
    );

// Returns the content.
return $content;
}}
4

1 に答える 1

1
function my_the_content_filter( $content ) {

// these two variables should reside this function scope, otherwise declare them as global

$expired_post = get_post_meta( $post->ID, 'deal_exp_dt', true);
$expired_post_time = strtotime($expired_post);



if(time() > $expired_post_time && !empty($expired_post)) {
    $content = sprintf(
        '<div id="expired_deal_post"><strong><span style="font-size: x-large;">EXPIRED</span></strong><br><span style="font-size: medium;">This deal has ended.</span></div>%s',
        $content
    );
 }

// Returns the content.
return $content;
}
于 2012-05-06T04:48:46.247 に答える