我对WP\\U查询有问题,我的场景:a)使用http://wordpress.org/extend/plugins/countries/b) 仅使用WP\\U查询获取国家及其代码。c) 正确重置查询。d) 使用自定义帖子类型e)使用元框sf)使用get\\u post\\u type()检索自定义帖子类型。
以下是代码片段:
$query_args = array(
\'post_type\' => \'countries\',
\'posts_per_page\' => -1,
\'post_status\' => \'publish\'
);
$countries_query = new WP_Query($query_args);
$countries_array = array();
if ($countries_query->have_posts()):
while ($countries_query->have_posts()) :
$countries_query->the_post();
$country_meta = get_post_custom($post->ID);
$country_code = $country_meta[\'country_code\'][0];
//$countries_array[$country_code] = $post->post_name;
$countries_array[$country_code] = $post->post_title;
endwhile;
endif;
wp_reset_postdata();
/*
* sorting countries alphabatically, keeps keys intact with "ksort"
*/
ksort($countries_array);
$GLOBALS[\'custom_countries\'] = $countries_array;
我正在将元框添加到我的自定义帖子类型中,使用if (get_post_type() == \'my_custom_post_type\'):
add_my_meta_box_for_custom_post_type();
endif;
get\\u post\\u type()返回“countries”,而不是全局$post,在本例中,全局$post是我的“my\\u custom\\u post\\u type”。我的代码有什么问题吗?????
请仅在您有具体答案而非一般答案或推测时回复。