我为ACF帖子设置了两个字段,特定于自定义帖子类型。
edition_number和artist_proofs
一些帖子类型没有任何这些数据集,而一些帖子类型有。我把这个函数放在content-single.php模板中,这样如果它有这个信息,它就应该通过。
出于某种原因,尽管我的帖子在这两个字段中都没有任何内容,但它仍然返回'Edition of‘。
function ffm_edition() {
if ( get_field( 'edition_number' ) && get_field( 'artist_proofs' ) ) {
echo 'Edition of ' , the_field( 'edition_number' ) , ', ' , the_field( 'artist_proofs' ) , 'APs';
} elseif ( empty( get_field( 'artist_proofs' ) ) ) {
echo 'Edition of ' , the_field( 'edition_number' );
} elseif ( empty( get_field( 'edition_number' ) && get_field( 'artist_proofs' ) ) ) {
//DO NOTHING
}
}关于这一点,我是否遗漏了什么?
发布于 2016-11-03 01:09:26
我意识到这是一个简单的上下文错误…
第二个检查只是检查artist_proofs字段是否为空。由于两者都为空,因此它将始终返回edition of。我需要检查有效字符串+空字符串:
} elseif ( get_field( 'edition_number' ) && empty( get_field( 'artist_proofs' ) ) ) {完整代码段:
function ffm_edition() {
if ( get_field( 'edition_number' ) && get_field( 'artist_proofs' ) ) {
echo 'Edition of ' , the_field( 'edition_number' ) , ' + ' , the_field( 'artist_proofs' ) , 'APs';
} elseif ( get_field( 'edition_number' ) && empty( get_field( 'artist_proofs' ) ) ) {
echo 'Edition of ' , the_field( 'edition_number' );
} elseif ( empty( get_field( 'edition_number' ) ) && empty( get_field( 'artist_proofs' ) ) ) {
//DO NOTHING
}
}https://stackoverflow.com/questions/40385201
复制相似问题