@Arh1diablo

Сортировка WP через post__in, как правильно собрать массив для этого поля?

Суть такова, получаю массив в таком виде:
Array ( [0] => Array ( [count] => 0 [ID] => 327 ) [1] => Array ( [count] => 0 [ID] => 326 ) [2] => Array ( [count] => 0 [ID] => 325 ) [3] => Array ( [count] => 0 [ID] => 324 ) [4] => Array ( [count] => 0 [ID] => 323 ) [5] => Array ( [count] => 0 [ID] => 322 ) [6] => Array ( [count] => 0 [ID] => 321 ) [7] => Array ( [count] => 0 [ID] => 320 ) [8] => Array ( [count] => 0 [ID] => 319 ) [9] => Array ( [count] => 0 [ID] => 318 ) [10] => Array ( [count] => 0 [ID] => 317 ) [11] => Array ( [count] => 0 [ID] => 316 ) [12] => Array ( [count] => 0 [ID] => 315 ) [13] => Array ( [count] => 0 [ID] => 314 ) [14] => Array ( [count] => 0 [ID] => 313 ) [15] => Array ( [count] => 0 [ID] => 312 ) [16] => Array ( [count] => 0 [ID] => 310 ) [17] => Array ( [count] => 0 [ID] => 309 ) [18] => Array ( [count] => 0 [ID] => 308 ) [19] => Array ( [count] => 0 [ID] => 307 ) [20] => Array ( [count] => 0 [ID] => 306 ) [21] => Array ( [count] => 0 [ID] => 305 ) [22] => Array ( [count] => 0 [ID] => 304 ) [23] => Array ( [count] => 0 [ID] => 303 ) [24] => Array ( [count] => 0 [ID] => 302 ) [25] => Array ( [count] => 0 [ID] => 235 ) [26] => Array ( [count] => 0 [ID] => 234 ) [27] => Array ( [count] => 0 [ID] => 233 ) [28] => Array ( [count] => 0 [ID] => 230 ) [29] => Array ( [count] => 0 [ID] => 225 ) [30] => Array ( [count] => 0 [ID] => 223 ) [31] => Array ( [count] => 0 [ID] => 222 ) [32] => Array ( [count] => 0 [ID] => 217 ) [33] => Array ( [count] => 0 [ID] => 215 ) [34] => Array ( [count] => 0 [ID] => 214 ) [35] => Array ( [count] => 0 [ID] => 213 ) [36] => Array ( [count] => 0 [ID] => 212 ) [37] => Array ( [count] => 0 [ID] => 211 ) [38] => Array ( [count] => 0 [ID] => 207 ) [39] => Array ( [count] => 0 [ID] => 206 ) [40] => Array ( [count] => 0 [ID] => 205 ) [41] => Array ( [count] => 0 [ID] => 202 ) [42] => Array ( [count] => 0 [ID] => 200 ) [43] => Array ( [count] => 0 [ID] => 199 ) [44] => Array ( [count] => 0 [ID] => 197 ) [45] => Array ( [count] => 0 [ID] => 196 ) [46] => Array ( [count] => 0 [ID] => 194 ) [47] => Array ( [count] => 0 [ID] => 192 ) [48] => Array ( [count] => 0 [ID] => 189 ) [49] => Array ( [count] => 0 [ID] => 188 ) [50] => Array ( [count] => 0 [ID] => 182 ) [51] => Array ( [count] => 0 [ID] => 181 ) [52] => Array ( [count] => 0 [ID] => 179 ) [53] => Array ( [count] => 0 [ID] => 178 ) [54] => Array ( [count] => 0 [ID] => 176 ) [55] => Array ( [count] => 0 [ID] => 175 ) [56] => Array ( [count] => 0 [ID] => 173 ) [57] => Array ( [count] => 0 [ID] => 170 ) [58] => Array ( [count] => 0 [ID] => 168 ) [59] => Array ( [count] => 0 [ID] => 165 ) [60] => Array ( [count] => 0 [ID] => 161 ) [61] => Array ( [count] => 0 [ID] => 156 ) [62] => Array ( [count] => 0 [ID] => 154 ) [63] => Array ( [count] => 0 [ID] => 151 ) [64] => Array ( [count] => 0 [ID] => 148 ) [65] => Array ( [count] => 1 [ID] => 144 ) [66] => Array ( [count] => 0 [ID] => 135 ) [67] => Array ( [count] => 0 [ID] => 132 ) [68] => Array ( [count] => 0 [ID] => 131 ) [69] => Array ( [count] => 0 [ID] => 126 ) [70] => Array ( [count] => 0 [ID] => 125 ) [71] => Array ( [count] => 0 [ID] => 122 ) [72] => Array ( [count] => 0 [ID] => 119 ) [73] => Array ( [count] => 0 [ID] => 118 ) [74] => Array ( [count] => 0 [ID] => 117 ) [75] => Array ( [count] => 0 [ID] => 114 ) [76] => Array ( [count] => 0 [ID] => 112 ) [77] => Array ( [count] => 0 [ID] => 111 ) [78] => Array ( [count] => 0 [ID] => 110 ) [79] => Array ( [count] => 0 [ID] => 108 ) [80] => Array ( [count] => 0 [ID] => 107 ) [81] => Array ( [count] => 1 [ID] => 106 ) [82] => Array ( [count] => 0 [ID] => 105 ) [83] => Array ( [count] => 0 [ID] => 104 ) [84] => Array ( [count] => 1 [ID] => 103 ) [85] => Array ( [count] => 0 [ID] => 102 ) [86] => Array ( [count] => 0 [ID] => 100 ) [87] => Array ( [count] => 0 [ID] => 97 ) [88] => Array ( [count] => 0 [ID] => 95 ) [89] => Array ( [count] => 0 [ID] => 94 ) [90] => Array ( [count] => 0 [ID] => 88 ) [91] => Array ( [count] => 0 [ID] => 86 ) [92] => Array ( [count] => 0 [ID] => 81 ) [93] => Array ( [count] => 0 [ID] => 80 ) [94] => Array ( [count] => 0 [ID] => 78 ) [95] => Array ( [count] => 2 [ID] => 77 ) [96] => Array ( [count] => 0 [ID] => 76 ) [97] => Array ( [count] => 0 [ID] => 74 ) [98] => Array ( [count] => 0 [ID] => 55 ) )


После прогоняю через arsort получаю массив в нужной мне сортировке:
Array ( [95] => Array ( [count] => 2 [ID] => 77 ) [65] => Array ( [count] => 1 [ID] => 144 ) [81] => Array ( [count] => 1 [ID] => 106 ) [84] => Array ( [count] => 1 [ID] => 103 ) [0] => Array ( [count] => 0 [ID] => 327 ) [1] => Array ( [count] => 0 [ID] => 326 ) [2] => Array ( [count] => 0 [ID] => 325 ) [3] => Array ( [count] => 0 [ID] => 324 ) [4] => Array ( [count] => 0 [ID] => 323 ) [5] => Array ( [count] => 0 [ID] => 322 ) [6] => Array ( [count] => 0 [ID] => 321 ) [7] => Array ( [count] => 0 [ID] => 320 ) [8] => Array ( [count] => 0 [ID] => 319 ) [9] => Array ( [count] => 0 [ID] => 318 ) [10] => Array ( [count] => 0 [ID] => 317 ) [11] => Array ( [count] => 0 [ID] => 316 ) [12] => Array ( [count] => 0 [ID] => 315 ) [13] => Array ( [count] => 0 [ID] => 314 ) [14] => Array ( [count] => 0 [ID] => 313 ) [15] => Array ( [count] => 0 [ID] => 312 ) [16] => Array ( [count] => 0 [ID] => 310 ) [17] => Array ( [count] => 0 [ID] => 309 ) [18] => Array ( [count] => 0 [ID] => 308 ) [19] => Array ( [count] => 0 [ID] => 307 ) [20] => Array ( [count] => 0 [ID] => 306 ) [21] => Array ( [count] => 0 [ID] => 305 ) [22] => Array ( [count] => 0 [ID] => 304 ) [23] => Array ( [count] => 0 [ID] => 303 ) [24] => Array ( [count] => 0 [ID] => 302 ) [25] => Array ( [count] => 0 [ID] => 235 ) [26] => Array ( [count] => 0 [ID] => 234 ) [27] => Array ( [count] => 0 [ID] => 233 ) [28] => Array ( [count] => 0 [ID] => 230 ) [29] => Array ( [count] => 0 [ID] => 225 ) [30] => Array ( [count] => 0 [ID] => 223 ) [31] => Array ( [count] => 0 [ID] => 222 ) [32] => Array ( [count] => 0 [ID] => 217 ) [33] => Array ( [count] => 0 [ID] => 215 ) [34] => Array ( [count] => 0 [ID] => 214 ) [35] => Array ( [count] => 0 [ID] => 213 ) [36] => Array ( [count] => 0 [ID] => 212 ) [37] => Array ( [count] => 0 [ID] => 211 ) [38] => Array ( [count] => 0 [ID] => 207 ) [39] => Array ( [count] => 0 [ID] => 206 ) [40] => Array ( [count] => 0 [ID] => 205 ) [41] => Array ( [count] => 0 [ID] => 202 ) [42] => Array ( [count] => 0 [ID] => 200 ) [43] => Array ( [count] => 0 [ID] => 199 ) [44] => Array ( [count] => 0 [ID] => 197 ) [45] => Array ( [count] => 0 [ID] => 196 ) [46] => Array ( [count] => 0 [ID] => 194 ) [47] => Array ( [count] => 0 [ID] => 192 ) [48] => Array ( [count] => 0 [ID] => 189 ) [49] => Array ( [count] => 0 [ID] => 188 ) [50] => Array ( [count] => 0 [ID] => 182 ) [51] => Array ( [count] => 0 [ID] => 181 ) [52] => Array ( [count] => 0 [ID] => 179 ) [53] => Array ( [count] => 0 [ID] => 178 ) [54] => Array ( [count] => 0 [ID] => 176 ) [55] => Array ( [count] => 0 [ID] => 175 ) [56] => Array ( [count] => 0 [ID] => 173 ) [57] => Array ( [count] => 0 [ID] => 170 ) [58] => Array ( [count] => 0 [ID] => 168 ) [59] => Array ( [count] => 0 [ID] => 165 ) [60] => Array ( [count] => 0 [ID] => 161 ) [61] => Array ( [count] => 0 [ID] => 156 ) [62] => Array ( [count] => 0 [ID] => 154 ) [63] => Array ( [count] => 0 [ID] => 151 ) [64] => Array ( [count] => 0 [ID] => 148 ) [66] => Array ( [count] => 0 [ID] => 135 ) [67] => Array ( [count] => 0 [ID] => 132 ) [68] => Array ( [count] => 0 [ID] => 131 ) [69] => Array ( [count] => 0 [ID] => 126 ) [70] => Array ( [count] => 0 [ID] => 125 ) [71] => Array ( [count] => 0 [ID] => 122 ) [72] => Array ( [count] => 0 [ID] => 119 ) [73] => Array ( [count] => 0 [ID] => 118 ) [74] => Array ( [count] => 0 [ID] => 117 ) [75] => Array ( [count] => 0 [ID] => 114 ) [76] => Array ( [count] => 0 [ID] => 112 ) [77] => Array ( [count] => 0 [ID] => 111 ) [78] => Array ( [count] => 0 [ID] => 110 ) [79] => Array ( [count] => 0 [ID] => 108 ) [80] => Array ( [count] => 0 [ID] => 107 ) [82] => Array ( [count] => 0 [ID] => 105 ) [83] => Array ( [count] => 0 [ID] => 104 ) [85] => Array ( [count] => 0 [ID] => 102 ) [86] => Array ( [count] => 0 [ID] => 100 ) [87] => Array ( [count] => 0 [ID] => 97 ) [88] => Array ( [count] => 0 [ID] => 95 ) [89] => Array ( [count] => 0 [ID] => 94 ) [90] => Array ( [count] => 0 [ID] => 88 ) [91] => Array ( [count] => 0 [ID] => 86 ) [92] => Array ( [count] => 0 [ID] => 81 ) [93] => Array ( [count] => 0 [ID] => 80 ) [94] => Array ( [count] => 0 [ID] => 78 ) [96] => Array ( [count] => 0 [ID] => 76 ) [97] => Array ( [count] => 0 [ID] => 74 ) [98] => Array ( [count] => 0 [ID] => 55 ) )


Далее, прогоняю полученный массив, через foreach и implode получаю переменную с такой инфой:
77,144,106,103,327,326,325,324,323,322,321,320,319,318,317,316,315,314,313,312,310,309,308,307,306,305,304,303,302,235,234,233,230,225,223,222,217,215,214,213,212,211,207,206,205,202,200,199,197,196,194,192,189,188,182,181,179,178,176,175,173,170,168,165,161,156,154,151,148,135,132,131,126,125,122,119,118,117,114,112,111,110,108,107,105,104,102,100,97,95,94,88,86,81,80,78,76,74,55


А, в запрос WP_Query параметр post__in ( который должен выглядеть как [77,327,144,106,103] ) не могу подставить, мозгов не хватает, подскажите, что я не так делаю ?
  • Вопрос задан
  • 57 просмотров
Решения вопроса 1
с помощью foreach делайте новый массив.

$posts = array(
	95 => array( 'count' => 2, 'ID' => 77 ),
	65 => array( 'count' => 1, 'ID' => 144 ),
	81 => array( 'count' => 1, 'ID' => 106 ),
	84 => array( 'count' => 1, 'ID' => 103 ),
	0 => array( 'count' => 0, 'ID' => 327 ),
	1 => array( 'count' => 0, 'ID' => 326 ),
	2 => array( 'count' => 0, 'ID' => 325 )
);

$ids = array();

foreach ($posts as $post) {
	$ids[] = $post['ID'];
}
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы