Can't assign the value of the_field() to a variable

寵の児 提交于 2019-12-02 09:38:05

问题


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.

If I do:

<?php include "submenu/abc.php" ?>

This works fine. But I need to do something like:

<?php 

    $file = the_field(ACFfield);
    include($file);

?>

This, however just prints out "submenu/abc.php", from the first line (which I wouldn't want visible anyway).

What am I doing wrong?


回答1:


the_field(ACFfield); doesn't return anything. It just prints the filename out. Use get_field() instead, which will return the value.



来源:https://stackoverflow.com/questions/32329943/cant-assign-the-value-of-the-field-to-a-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!