Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/wordpress/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Wordpress自定义字段不在循环中显示html_Php_Wordpress_Custom Post Type_Nested Loops_Advanced Custom Fields - Fatal编程技术网

Php Wordpress自定义字段不在循环中显示html

Php Wordpress自定义字段不在循环中显示html,php,wordpress,custom-post-type,nested-loops,advanced-custom-fields,Php,Wordpress,Custom Post Type,Nested Loops,Advanced Custom Fields,我对PHP有点陌生,所以不要恨我。 我正在使用高级自定义字段,我有问题 我需要访问注册人员的字段,他们可以输入的数据之一是他们的社交网络。然而,这些可以是0,1,2,3,他们想要的每一个社交网络 我想要一个“if语句”来检查字段是否填充了一些信息,然后显示它,或者不显示它,但是它只显示“the_field”文本,它去掉了它周围的所有HTML标记 下面是我在PHP(have_posts())循环中使用的最新代码 这就是我们所看到的。应该出现在Twitter上: 这是开发人员的浏览器控

我对PHP有点陌生,所以不要恨我。 我正在使用高级自定义字段,我有问题

我需要访问注册人员的字段,他们可以输入的数据之一是他们的社交网络。然而,这些可以是0,1,2,3,他们想要的每一个社交网络

我想要一个“if语句”来检查字段是否填充了一些信息,然后显示它,或者不显示它,但是它只显示“the_field”文本,它去掉了它周围的所有HTML标记

下面是我在PHP(have_posts())循环中使用的最新代码

这就是我们所看到的。应该出现在Twitter上:

这是开发人员的浏览器控制台源代码,Twitter标记上没有HTML或PHP:

我做错了什么


任何帮助都将不胜感激。谢谢。

如果您想将自定义字段数据转换为变量,则必须使用类似于
的get_字段('custom_field_name')不象
_字段('custom_field_name')用以下代码替换您的代码

<ul class="social">
    <li><a target="_blank" class="facebook" href="<?php the_field('facebook'); ?>">X</a></li>
    <li><a target="_blank" class="linkedin" href="<?php the_field('linkedin'); ?>">v</a></li>
    <?php 
    $strtwitter = get_field('twitter');
    $strtwitter = strlen($strtwitter);
    if ($strtwitter > 10) :
        ?>
        <li><a target="_blank" class="twitter" href="<?php the_field('twitter'); ?>">_</a></li>
    <?php endif; ?>
</ul>

您必须对条件语句使用
get\u字段(“text\u字段”)

if( get_field( "text_field" ) ): ?>
    <p><?php the_field( "text_field" ); ?></p>
<?php endif;
if(获取字段(“文本字段”):?>


下面的评论是错误的:$strtwitter=get_the_字段('twitter');获取\u字段->应该是唯一的获取\u字段。然后它就完美地工作了。非常感谢。欢迎来到SO@BrunoConfortin。请将此答案标记为正确答案,不要在标题中添加“已解决”。抱歉,没有看到“正确答案”图标。谢谢:D
if( get_field( "text_field" ) ): ?>
    <p><?php the_field( "text_field" ); ?></p>
<?php endif;