-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathpmxi_acf_custom_field.php
38 lines (34 loc) · 1.09 KB
/
pmxi_acf_custom_field.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
/**
* ================================================
* Filter: pmxi_acf_custom_field
* ================================================
*
* Filter for ACF custom field values.
*
* @param $value - Imported value
* @param $pid - The post ID.
* @param $name - The field name.
*
*/
add_filter( 'pmxi_acf_custom_field', 'wp_all_import_pmxi_acf_custom_field', 10, 3 );
function wp_all_import_pmxi_acf_custom_field( $value, $pid, $name ) {
// Code here.
}
// ----------------------------
// Example uses below
// ----------------------------
/**
* Example: only update ACF field if the imported value is not empty. Only works if "Choose which data to update" is enabled in the import settings.
*
*/
add_filter( 'pmxi_acf_custom_field', 'wp_all_import_pmxi_acf_custom_field', 10, 3 );
function wp_all_import_pmxi_acf_custom_field( $value, $pid, $name ) {
// get existing value
$existing = get_post_meta( $pid, $name, true );
if ( empty( $value ) ) {
// The field is empty in the import, so use the existing value in the post.
$value = $existing;
}
return $value;
}