Wordpress get_terms не допускает переменную массива - PullRequest
0 голосов
/ 23 декабря 2019

Хорошо, это один из тех странных примеров, когда он пытается передать сгенерированный массив в get_terms, пробовал его напрямую с помощью $ compiledList, косвенно с помощью implode () и перестраивает массив в строку, не повезло, есть что-то? просто я скучаю?

<code>$thearray = [];
$thelister = [];
$compiledList = [];
$args = array(
    'meta_query'  => array(
                    '_stock_status' => 'instock'
        )
);
foreach( wc_get_products(array($args, 'limit' => -1)) as $product ){

    foreach( $product->get_attributes() as $attr_name => $attr ){

        $terms = "pa_" . strtolower(wc_attribute_label( $attr_name )) .",";
        array_push($thelister, $terms);
        // or get_taxonomy( $attr_name )->labels->singular_name;

    }
}
        $thenames = array_unique($thelister);
        foreach($thenames as $tname)
        {
            array_push($compiledList, $tname);
        }
$compiledList = implode('', $compiledList);
$compiledList = str_replace('pa_', '"pa_', $compiledList);
$compiledList = str_replace(',', '",', $compiledList);
$compiledList = substr($compiledList, 0, -1);
$compiledList = strval($compiledList);
echo $compiledList;


print("<pre>".print_r($compiledList,true)."
"); $ theterms = get_terms ([$ compiledList]); foreach ($ theterms as $ term) {$ Categories = $ term-> name; $ Categories = str_replace ('& ',' и ', $ Categories); array_push ($ thearray, $ Categories);}
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...