我正在使用来自不同表的两个查询。但我需要在一个循环中输出它们。 $postexpire
让我得到了Metavalue。 $query1
让我成为GUID。
我的循环首先运行metavalue然后我想运行GUID循环,但是一次一次。
这是我的代码:
<?php
$postexpire = "SELECT meta.meta_value, meta.post_id FROM $wpdb->postmeta meta INNER JOIN $wpdb->posts post ON meta.post_id = post.ID WHERE post_type = 'auction' AND meta_key = 'closed' AND post_status = 'publish' ORDER BY post.post_title DESC";
$query1 = $wpdb->get_results("SELECT pst.guid FROM $wpdb->posts pst INNER JOIN $wpdb->postmeta mt ON pst.ID = mt.post_id WHERE post_type = 'auction' AND meta_key = 'closed' AND post_status = 'publish' ORDER BY pst.post_title DESC");
//print_r($query1);
$query = $wpdb->get_results($postexpire);
foreach ($query as $results) {
$pid = $results->ID;
$closed = $results->meta_value;
if($closed == 1){
?>
<p><span class="custom-offline-color">Offline</span></p>
<?php
} else {
?>
<p><a class="custom-color" target="_blank" href="<?php foreach ($query1 as $posturlqueryresults) { $url = $posturlqueryresults->guid; echo $url; } ?>">View</a></p>
<?php
}
}
?>
谢谢!请帮帮我!
答案 0 :(得分:0)
你可以尝试一下这个:
foreach ($query as $index=>$results) {
$pid = $results->ID;
$closed = $results->meta_value;
if($closed == 1){
?>
<p><span class="custom-offline-color">Offline</span></p>
<?php
} else {
?>
<p><a class="custom-color" target="_blank" href="<?php $url = $query1[$index]->guid; echo $url; } ?>">View</a></p>
<?php
}