无法将the_field()的值分配给变量 [英] Can't assign the value of the_field() to a variable
本文介绍了无法将the_field()的值分配给变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Wordpress中使用高级自定义字段。我在字段中有一个文件路径(在字段 ACFfield中说 submenu / abc.php)。我想在网页上包含该信息。
I'm using Advanced Custom Fields in Wordpress. I have a file path in a field (say "submenu/abc.php" in field "ACFfield"). I want to include that info on a webpage.
如果我这样做:
<?php include "submenu/abc.php" ?>
这很好。但我需要做类似的事情:
This works fine. But I need to do something like:
<?php
$file = the_field(ACFfield);
include($file);
?>
但这只是从第一行打印出 submenu / abc.php
This, however just prints out "submenu/abc.php", from the first line (which I wouldn't want visible anyway).
我在做什么错了?
推荐答案
the_field(ACFfield);
不返回任何内容。它只是打印出文件名。改用 get_field()
将返回值。
the_field(ACFfield);
doesn't return anything. It just prints the filename out. Use get_field()
instead, which will return the value.
这篇关于无法将the_field()的值分配给变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文