【问题标题】:PHP Variable within Wordpress shortcodeWordpress 短代码中的 PHP 变量
【发布时间】:2014-08-27 05:08:51
【问题描述】:

我需要使用简码,但将客户输入的变量插入到简码中。

我已尝试使用以下内容:

echo do_shortcode('[su_accordion][su_spoiler title="What is your name and your position in       the company?"]'.the_field('whats_your_name_and_your_position_in_the_company').'[/su_spoiler][/su_accordion]');

但它只是将回显文本放在手风琴简码http://prntscr.com/3zzfv9 上方。

有什么想法吗?

谢谢!

【问题讨论】:

  • 我不清楚您的评论“......将客户输入的变量插入短代码”客户何时在此页面或网站上的其他地方执行此操作?我假设在其他地方,但这不清楚。我假设 the_field(cat slug name?) 在生成此页面之前已填充。有了这些假设,这个短代码看起来不错。在您的程序的这个区域之前/之后可能存在一些编码风格问题?请注意:当您可以轻松使用本机 stackoverflow 工具时,为什么还要让我们看到那个可怕的轻量级垃圾邮件广告网站?
  • 我假设的问题是:'.the_field('whats_your_name_and_your_position_in_the_company')。我是否需要转义 'whats_your_name_and_your_position_in_the_company' 上的撇号?
  • hmm.. do_shortcode('..."..."..' . the_field('...') . '...' ) 对我来说看起来绝对没问题.. I'我确定您已经尝试过 the_field("..."),对吧?我怀疑代码中的其他地方有遗漏?

标签: php wordpress accordion


【解决方案1】:

在这里找到答案https://wordpress.stackexchange.com/questions/77384/echo-do-shortcode-with-custom-field-not-working

需要使用 get_field 而不是 the_field

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2013-11-24
    • 2020-01-29
    • 1970-01-01
    • 2013-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多