doutang7707 2016-04-07 18:55
浏览 56

使用$ wpdb和get_query_var从Wordpress DB获取信息

I've been successful in doing most of what I want to do. I'm creating profile pages on an association website where staff will be able to see all of a members information on nicely formatted profile pages. I'm using the get_query_var function to query the page (http://yoursite.com/profile/?profile=1783 for example).

On the profile pages themselves I load this code first:

<?php  $vars = get_query_var( 'profile' ); ?>

And then below I run the queries. Such as:

 <?php $user_info = get_userdata((int) $vars); echo $user_info->last_activity . "
"; ?>

(The (int) $vars grabs the user ID from the url.)

This is working great for user meta data, but when I try to grab data using $wpdb from other tables I'm having some trouble. For example, I'm trying to grab data from a MemberPress table on transactions. It returns data but not for the right user. For some reason it always returns values for user 756.

Here's the code I'm using.

<?php $status = $wpdb->get_var("SELECT status FROM wp_acfzia_mepr_transactions WHERE user_id = '(int) $vars);' "); echo $status; ?>

It's clearly working but not getting the "user_id" value correct. It always returns user 756. Pretty bizarre. Any help is appreciated. Thanks.

  • 写回答

1条回答 默认 最新

  • dongtang6681 2016-04-07 21:11
    关注

    I figured it out. Just $vars instead of (int) $vars);

    评论

报告相同问题?

悬赏问题

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