我有一个很好的循环,但我必须检查post对象(“houses”)的自定义字段是否有内容。我用“isset”试了一下,什么都没发生。也试过“isset”,但问题是一样的。
$args2 = array (
\'numberposts\' => -1,
\'post_type\' => \'houses\'
);
$custom_posts2 = get_posts($args2);
foreach ( $custom_posts2 as $custom_post2 ) {
// check here if custom post type opjects custom field "sz_website" has content
if ( !empty ($custom_post2->post_website)) {
echo \'<div class="wpcf7-list-item-field">\' . $custom_post2->sz_website . \'</div>\';
} else {
echo "do nothing";
}
}
wp_reset_postdata();