根据所需的范围,在布局的开头或函数文件中声明一个数组,并使用get\\u posts和键作为post ID使用所有标注栏填充数组。
然后,您将拥有一个全局波段阵列,并可以在任何需要的地方从每个波段提取信息。
我所研究的一些类似代码:
global $bands;
$bands = array();
$bandPosts = get_posts(array(\'numberposts\' => -1, \'post_type\' => \'lmfBand\', \'order\' => \'ASC\', \'orderby\' => \'title\'));
foreach($bandPosts as $bandPost) {
$bands["{$bandPost->ID}"] = array($bandPost->post_title,$bandPost->post_name);
}
然后,要获得乐队名称,只需使用:$bands[“{band\\u id}”][0](在上面的版本中)
您还可以将每个band设置为stdClass对象,而不仅仅是一个值数组。