我试图在循环中显示一个名为“my\\u custom\\u field”的自定义字段:
$custom_array = get_post_custom( get_the_ID() );
echo $custom_array[\'my_custom_field\'];
此代码显示“array”。它是否应该显示自定义字段的值?我试图在循环中显示一个名为“my\\u custom\\u field”的自定义字段:
$custom_array = get_post_custom( get_the_ID() );
echo $custom_array[\'my_custom_field\'];
此代码显示“array”。它是否应该显示自定义字段的值?get_post_custom()
将返回数组的数组。您需要:
echo $custom_array[\'my_custom_field\'][0];
或者,您可以使用get_post_meta()
使用$single
标记为true
:echo get_post_meta( get_the_ID(), \'my_custom_field\', true );