我想通过为我的每个帖子提供特定编号来更新我的所有 custom_field。问题:我不想在里面添加 0 的数字。
$i = 1; // Start from 1
if ($ajax_query->have_posts()) :
while ($ajax_query->have_posts()) :
$ajax_query->the_post();
update_post_meta( get_the_ID(), 'the_custom_field', $i++ );
// $i++ will be the specific number for each my post.
endwhile;
endif;
现在,我的帖子 1 有 the_custom_field 1,我的帖子 2 有 the_custom_field 2.... 我的帖子 10 有 the_custom_field 10
但它应该是这样的:
post1 的 the_custom_field 应该是 1
post2 的 the_custom_field 应该是 2
post3 的 the_custom_field 应该是 3
...
post10 的 the_custom_field 应该是 11
post11 的 the_custom_field 应该是 12 等
慕勒3428872