【问题标题】:Wordpress- Echo PHP into ShortcodeWordpress-将 PHP 回显到简码中
【发布时间】:2014-02-18 15:53:03
【问题描述】:

我在使用短代码时遇到了一点问题。我希望它获取变量并将其放置在通常应该去那里的文本的位置,但不是工作它只是不加载它,即使我已经用 echo 测试了它以查看它是否放置任何东西出来了。

<?php 
    $artistslug = the_field('artist_cat_slug');
    echo $artistslug;    // Here for test reasons
    echo do_shortcode('[product_category category="'.$artistslug.'"]');
?>

任何帮助将不胜感激。

【问题讨论】:

  • the_field() 不是默认的 WordPress 功能 - 这是来自插件吗?
  • 对不起,我应该澄清一下这是高级自定义字段插件,我的错

标签: php wordpress shortcode


【解决方案1】:

很可能,the_field() 显示该值。您正在使用的插件可能有一个相应的函数来返回值,例如get_the_field()。改用它。

clarification in comments之后编辑

来自documentation for the_field()强调我的):

显示指定字段的值。 (这个和echo get_field($field_name)一样)

没错。请改用get_field()

【讨论】:

  • Call to undefined function get_the_field() in /var/sites/i/inlandclothing.co.uk/public_html/wp-content/themes/inlandclothing/page-artist.php on line 27 当我把它作为 get_the_field 时我得到了这个
  • @MatthewArtiman:看拼写。这是get_field() 而不是get_the_field()
  • 成功了!非常感谢你,非常感谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-09-04
  • 1970-01-01
相关资源
最近更新 更多