如果在一个寻找城市的国家
$args = array (
\'post_type\' => \'cities\',
\'meta_key\' => \'country\',
\'meta_value\' => get_the_ID()
);
这假设
"Country > Name* > [drop down]" 您可以使用屏幕截图保存所选值
post_meta
并且正在保存国家的邮政ID。(如果没有,请调整或指定)。
更新以列出城市并检索其country\\u名称,假设下拉列表仅存储国家的post\\u标题,您可以执行以下操作:
$cities = get_posts(array (
\'post_type\' => \'cities\',
\'numberposts\' => \'-1\',
));
foreach ($cities as $city) {
$country_name = get_post_meta($city->ID,\'country_name\',true);
// to get the full country, if country_name is just the post title (and not ID) you could do
# $country = get_page_by_title( $country_name, \'object\', \'country\' );
echo "<pre>City: {$city->post_title} is in country: {$country_name}</pre>":
}