简体   繁体   English

Wordpress function 使用get_results ARRAY_A响应问题

[英]Wordpress function using get_results ARRAY_A response problem

thanks for looking at my issue.感谢您查看我的问题。 So I am trying to return each term of the five that my query is selecting.所以我试图返回我的查询选择的五个术语中的每个术语。 Here is my function:这是我的 function:

function VD_top_terms(){
global $wpdb;
$VDtermsSQL = "SELECT DISTINCT AN_terms.name from AN_posts INNER JOIN AN_term_relationships on AN_term_relationships.object_id = AN_posts.ID INNER JOIN AN_term_taxonomy on AN_term_taxonomy.term_taxonomy_id=AN_term_relationships.term_taxonomy_id INNER JOIN AN_terms on AN_term_taxonomy.term_id=AN_terms.term_id where AN_posts.post_date_gmt >= NOW() - INTERVAL 1 DAY and AN_term_taxonomy.taxonomy ='post_tag' group by AN_terms.name order by count DESC limit 5";
$VDtResults = $wpdb->get_results($VDtermsSQL, ARRAY_A);
foreach( $VDtResults as $VDsinTerm) {
    echo $VDsinTerm;
}
}

This is the response:这是回应:

ArrayArrayArrayArrayArray

Not sure where I am going wrong here.不知道我哪里错了。 If i remove the foreach and echo statement and substitute it for a printr statement I get the following which is why I switched over to the foreach loop and added ARRAY_A.如果我删除 foreach 和 echo 语句并将其替换为 printr 语句,我将得到以下结果,这就是我切换到 foreach 循环并添加 ARRAY_A 的原因。

Array ( [0] => stdClass Object ( [name] => Cat ) [1] => stdClass Object ( [name] => Door ) [2] => stdClass Object ( [name] => School ) [3] => stdClass Object ( [name] => falls ) [4] => stdClass Object ( [name] => Court ) )

I am trying to get the results Cat, Door, School, Falls, Court to display on the page.我正在尝试将结果 Cat、Door、School、Falls、Court 显示在页面上。 Any help would be appreciated.任何帮助,将不胜感激。 Thanks谢谢

I figured it out.我想到了。 Instead of ARRAY_A use OBJECT. Changed the echo to a print_r statement and defined the column name where the output is.使用 OBJECT 而不是 ARRAY_A。将 echo 更改为 print_r 语句并定义 output 所在的列名称。

function VD_top_terms(){
global $wpdb;
$VDtermsSQL = "SELECT DISTINCT AN_terms.name from AN_posts INNER JOIN AN_term_relationships on AN_term_relationships.object_id = AN_posts.ID INNER JOIN AN_term_taxonomy on AN_term_taxonomy.term_taxonomy_id=AN_term_relationships.term_taxonomy_id INNER JOIN AN_terms on AN_term_taxonomy.term_id=AN_terms.term_id where AN_posts.post_date_gmt >= NOW() - INTERVAL 1 DAY and AN_term_taxonomy.taxonomy ='post_tag' group by AN_terms.name order by count DESC limit 5";
    $VDtResults = $wpdb->get_results($VDtermsSQL, OBJECT);
    foreach( $VDtResults as $VDsinTerm) {
        print_r($VDsinTerm->name);
    }
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM