在函数中添加以下代码。php
for acf
function get_all_meta($type){
global $wpdb;
$result = $wpdb->get_results($wpdb->prepare(
"SELECT post_id,meta_key,meta_value FROM wp_posts,wp_postmeta WHERE post_type = %s
AND wp_posts.ID = wp_postmeta.post_id", $type
), ARRAY_A);
return $result;
}
function acf(){
$options = array();
$acf = get_all_meta(\'acf\');
foreach($acf as $key => $value){
$options[\'post_type\'][$value[\'post_id\']][\'post_id\'] = $value[\'post_id\'];
$test = substr($value[\'meta_key\'], 0, 6);
if($test === \'field_\'){
$post_types = maybe_unserialize( $value[\'meta_value\'] );
$options[\'post_type\'][$value[\'post_id\']][\'key\'][] = $post_types[\'key\'];
$options[\'post_type\'][$value[\'post_id\']][\'key\'][] = $post_types[\'name\'];
$options[\'post_type\'][$value[\'post_id\']][\'key\'][] = $post_types[\'type\'];
}
if($value[\'meta_key\'] == \'rule\'){
$post_types = maybe_unserialize( $value[\'meta_value\'] );
$options[\'post_type\'][$value[\'post_id\']][\'post_types\'] = $post_types[\'value\'];
}
}
return $options;
}
这将为您提供acf的post meta key的数组值。
How to use
foreach(acf() as $key => $value){
update_post_meta(76, $value[\'type\'], \'Steve\');
}
For pods
函数pods(){global$wpdb;//获取pods post type id。
$result = $wpdb->get_results($wpdb->prepare(
"SELECT ID,post_title,post_parent FROM wp_posts WHERE post_type = %s", $type
), ARRAY_A);
// pods each field for a post type create separate post type so again query to get the field post type result.
$pods_field_post_type = array();
foreach($result as $value){
$pods_field_post_type = $wpdb->get_results($wpdb->prepare(
"SELECT ID,post_title,post_name FROM wp_posts WHERE post_type = %s
AND post_parent = %d
", \'_pods_field\',$value["ID"]
), ARRAY_A);
}
$fields = array();
foreach($pods_field_post_type as key => $value):
$podsAPI = new PodsAPI();
$pod = $podsAPI->load_pod( array( \'name\' => \'
post\' ));
$fields[] = $pod[\'fields\'][$value[\'post_name\']][\'type\'];
endforeach;
}
print_r($fields);
How to use
foreach($fields as $key => $value){
update_post_meta(76, $value, \'Steve\');
}
函数acf()和pods()为您提供该post类型的确切元键。如果复制并粘贴代码,则可能无法工作。
希望这个答案对你和其他人都有帮助。
让我知道你什么都不麻烦。