下面的代码在wordpress中产生以下输出-Array([0] => 393 [1] => 362 [2] => 361)。
我想将此数组([0] => 393 [1] => 362 [2] => 361)转换为数组(393,362,361),我想传递此信息数组到wordpress查询帖子。
<?php
$getphotoidfromurl = 5;
global $wpdb;
// $sqlselque = "SELECT post_id FROM wp_postmeta WHERE meta_key = 'metrodir_company_gallery' LIMIT 0 , 30";
$db_item = $wpdb->get_results($wpdb->prepare("SELECT post_id,meta_value FROM wp_postmeta WHERE meta_key = 'metrodir_company_gallery' LIMIT 0 , 30"));
$r1=array();
foreach ($db_item as $rs) {
//echo "hello";
//echo $rs->post_id;
$getphotos = $rs->meta_value;
$rr = explode(",", $getphotos);
$getphotocount = count($rr);
if ($getphotoidfromurl == $getphotocount) {
$newgettwo = $rs->post_id;
// print_r($array);
array_push($r1, $newgettwo);
}
}
print_r($r1);
exit;
global $wp_query;
query_posts(array(
'post_type' => array('company'),
'posts_per_page' => -1,
'orderby' => $orderby,
'order' => $order,
));
所以我的wordpress查询应该是这样的 -
query_posts(array(
'post_type' => array('company'),
'posts_per_page' => -1,
'orderby' => $orderby,
'order' => $order,
'p' => array(393,362,361)
答案 0 :(得分:0)
只需简单地输入$ r1,因为当我们print_r($ r1)时,你得到的$ r1就可以了。 它向我们展示了数组密钥索引
query_posts(array(
'post_type' => array('company'),
'posts_per_page' => -1,
'orderby' => $orderby,
'order' => $order,
'p' => $r1 //see here
e.g
$r1=array(393,362,361);
print_r($r1);
//result
Array ( [0] => 393 [1] => 362 [2] => 361 )