blanket11
4/20/2017 - 12:42 PM

[WordPress]acf pro 記事登録時とかに何を送ったか調べたい時

[WordPress]acf pro 記事登録時とかに何を送ったか調べたい時

<?php
/**
 * acf情報をPOSTで受け取り
 *
 * @param $key
 * @return string
 */
function get_acf_val($key) {
	$val = '';
	$acf_field = get_field_object( $key );
	$acf_key = $acf_field["key"];
	if ( isset( $_POST["acf"][$acf_key] ) ) {
		$val = $_POST["acf"][$acf_key];
	}
	return htmlspecialchars( $val, ENT_QUOTES );
}

function get_acf_val_repeater ($repeaterKey, $key){
	$val = '';
	$val_repeater = '';
	$acf_key = '';
	$acf_field_repeater = get_field_object( $repeaterKey );
	$acf_key_repeater = $acf_field_repeater["key"];
	if ( isset( $_POST["acf"][$acf_key_repeater] ) ) {
		$val_repeater = $_POST["acf"][$acf_key_repeater];
	}

	while (has_sub_field($repeaterKey)) {
		$acf_field = get_sub_field_object($key);
		$acf_key = $acf_field['key'];
		break;
	}

	foreach ($val_repeater as $val_inner) {
		$str = $val_inner[$acf_key];
		$val[] = ctype_digit($str) ? intval($str) : $str;
	}
	return $val;
}