【发布时间】:2021-07-10 14:12:47
【问题描述】:
我有一个自定义帖子类型,其中包含一些 ACF 字段。我还设置了一个 ACF 选项页面。
我正在尝试在更新选项页面中的文本字段中的所有自定义帖子上的文本字段,当更新选项页面时。
这是我尝试过的:
function update_global_flash_text(){
$current_page = get_current_screen()->base;
if($current_page == 'toplevel_page_options') {
function update_global_servicing_text() {
$args = array(
'post_type' => 'custom',
'nopaging' => true,
);
$the_query = new WP_Query( $args );
if ( $the_query->have_posts() ) {
while ( $the_query->have_posts() ) {
$the_query->the_post();
update_field('servicing_flash_text', $_POST['global_servicing_offer_text']);
}
}
wp_reset_postdata();
}
if(array_key_exists('post',$_POST)){
update_global_servicing_text();
}
}
}
add_action('admin_head','update_global_flash_text');
理想情况下,如果全局字段值已更改,我也只想更新帖子字段。
【问题讨论】:
-
只是为了翻转一些逻辑,您真的需要更新每个 CPT 吗?您可以直接从渲染选项中提取吗?根据您拥有的 CPT 数量,每个 CPT 的更新最终都会随着时间的推移而开始变慢,并且可能会超时。
标签: php database wordpress advanced-custom-fields