0

私の関数ファイルには、投稿をループし、投稿のfacebookとgoogle plus likesを一緒に追加し、値を投稿メタに保存するコードが少しありますが、値はpost_metaに一度だけ保存されています-それは更新しない!

ここで私の問題は何ですか、なぜ更新されないのですか?

これが私のコードです:

$the_query = new WP_Query( $args );

while ( $the_query->have_posts() ) : $the_query->the_post();

// Get Facebook Likes From FB Graph API
$data = file_get_contents('http://graph.facebook.com/?id='. get_permalink());
$obj = json_decode($data);
$like_no = intval($obj->{'shares'});

$html =  file_get_contents( "https://plusone.google.com/_/+1/fastbutton?url=".urlencode(get_permalink()));
    $doc = new DOMDocument();   $doc->loadHTML($html);
    $counter=$doc->getElementById('aggregateCount');
    $google_no = $counter->nodeValue;

   $shares_total = $like_no + $google_no;

// Add Facebook Likes to Post Meta
update_post_meta(get_the_ID(), '_mn_fb_likes', $shares_total);

endwhile;
wp_reset_postdata();
}
4

1 に答える 1

0

$query->the_post();グローバル変数を設定する$post必要があるため、置き換えることができるはずです

update_post_meta(get_the_ID(), '_mn_fb_likes', $shares_total);

update_post_meta( $post->ID, '_mn_fb_likes', $shares_total );

問題がget_the_ID()通話にある場合は、これで解決するはずです。(私はそれが問題であると 100% 確信しているわけではありませんが、少なくともこれにより、潜在的な原因としてそれが排除されます。)

于 2013-11-11T06:11:55.003 に答える