我有不到 1,000 个 lp_lesson
类型的帖子,我正在尝试能够遍历它们以将文本应用于特定的自定义字段。
下面的代码仅适用于其中的几个。可能性在10-15之间。我想知道是不是因为我正在使用wp_enqueue_scripts
?我还尝试在wp_login
上应用此更改。它们都更新了完全相同数量的帖子和完全相同的帖子。
我是 php 的新手,所以如果我完全做错了,请告诉我。
我确实相信循环在系统超时之前没有完成的问题,也许?我可以确认所有帖子都lp_lesson
,因此循环没有完成。也许$args
不能容纳这么大的阵列?任何提示都值得赞赏!
谢谢。
add_action( 'wp_enqueue_scripts', 'win_9388244_format_lp_lesson' );
function win_9388244_format_lp_lesson() {
//Get post type of lp_lesson
$args = array(
'post_type' => 'lp_lesson'
);
$posts = get_posts($args);
foreach($posts as $post) {
update_post_meta( $post->ID, 'wpk_icon_text', 'Test' );
}
}
get_posts的默认参数是:
$defaults = array(
'numberposts' => 5,
'category' => 0, 'orderby' => 'date',
'order' => 'DESC', 'include' => array(),
'exclude' => array(), 'meta_key' => '',
'meta_value' =>'', 'post_type' => 'post',
'suppress_filters' => true
);
这意味着,如果您没有在$args变量中指定这些值,WordPress 将默认使用这些值。如果你给数字柱一个值,那么wordpress将使用这个值,以及其他默认值。
您应该设置号码柱。例如:
$args = array(
'post_type' => 'lp_lesson',
'numberposts' => 99999
);
get_posts函数参考