仅当高级自定义字段的内容等于 0 时,我将如何调用此函数
function updateNumbers() {
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb-posts.post_status = 'publish' AND $wpdb->posts.post_type = 'post'";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 1440 ;
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
$counts++;
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
endforeach;
endif; remove_action ( 'publish_post', 'updateNumbers' );
}
add_action ( 'publish_post', 'updateNumbers' );
在此先感谢男孩和女孩!
++++++编辑++++++
为了澄清,这应该在上下文中描述函数:
div 由 ACF 插件控制的 wordpress 字段填充:
<?php $post_id = get_field('job-number'); ?>
div class="postID"><?php echo $post_id ?></div>
如果这个值等于 0 那么我想运行这个函数:
function updateNumbers() {
global $wpdb;
$querystr = "SELECT $wpdb->posts.* FROM $wpdb->posts WHERE $wpdb->posts.post_status = 'publish' AND $wpdb->posts.post_type =
'post'";
$pageposts = $wpdb->get_results($querystr, OBJECT);
$counts = 1440 ;
if ($pageposts):
foreach ($pageposts as $post):
setup_postdata($post);
$counts++;
add_post_meta($post->ID, 'incr_number', $counts, true);
update_post_meta($post->ID, 'incr_number', $counts);
endforeach;
endif; }
add_action ( 'publish_post', 'updateNumbers' );