I am having issue with WP_Query, My scenario: a) Using http://wordpress.org/extend/plugins/countries/ b) Using WP_Query to fetch countries and their codes only. c) resetting query properly. d) using custom post type e) using meta boxes f) using get_post_type() to retrieve the custom post type.
Here is code snippet:
$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;
and I am adding meta box to my custom post type, using
if (get_post_type() == 'my_custom_post_type'):
add_my_meta_box_for_custom_post_type();
endif;
and get_post_type() returns "countries" instead of global $post which is in this case my "my_custom_post_type".
Is there anything wrong with my code?????
Please reply only if you have specific answers not general answers or speculations.