douchan7552 2017-04-24 22:03
浏览 17
已采纳

在wordpress页面上使用SQL

Using a plugin I'm able to use PHP on page by using [insert_php] as a tag however, whenever I try using SQL it doesn't seem to work. I tried using:

global $wpdb;
$prepared = $wpdb->get_row(
    "SELECT SiteID, SiteName
    FROM $wpdb->Site
        WHERE SiteID = 1");

echo $prepared->SiteName;
echo "test";

All I'm getting is test on the page and I've tested to see if my sql statement was at fault and it seems to be working fine so I'm guessing there's an issue with $wpdb or the way I'm outputting the data.

  • 写回答

2条回答 默认 最新

  • douya1248 2017-04-24 22:35
    关注

    WordPress.org has a lot of detailed information in their reference.

    I think attempting to refer to $wpdb->Site is a likely suspect for why your code is not working. You will need to know the exact fields in the table to pull your information.

    Here is a reference for the wp_site table. I think you're actually looking for the 'domain' field, not 'sitename'.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本