我的 WordPress 代码如下:
Array ( [0] => 393 [1] => 362 [2] => 361 )
我想将此数组转换为
array(393,362,361)
并且我想将此数组传递到 WordPress 的查询帖子中。
$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 $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)
));
只需简单地输入 $r1,因为当我们 print_r($r1); 时,你的结果 $r1 就可以了; 它向我们显示数组键索引
query_posts(array(
'post_type' => array('company'),
'posts_per_page' => -1,
'orderby' => $orderby,
'order' => $order,
'p' => $r1 //see here
例如
$r1=array(393,362,361);
print_r($r1);
//result
Array ( [0] => 393 [1] => 362 [2] => 361 )