我正在使用WPML的wordpress多语言。这是我用来获取具有特色的房地产属性的代码:
<?php
$propMgr = new PropertiesManager();
$properties = $propMgr->getProperties('featured');
if(empty($properties)) {
return;
}
?>但是,这段代码每三次返回featured,即我所使用的所有三种语言。当选择英语语言时,我如何才能使它只返回英语,等等。
更新:
当我做print_r($properties);时
(
[0] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1128
[post_author] => 1
[post_date] => 2014-10-22 21:20:57
[post_date_gmt] => 2014-10-22 21:20:57
[post_content] =>
[post_title] => Villa Porto Taverna
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-porto-taverna
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-22 21:36:22
[post_modified_gmt] => 2014-10-22 21:36:22
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1128
)
[1] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1105
[post_author] => 1
[post_date] => 2014-10-22 21:20:57
[post_date_gmt] => 2014-10-22 21:20:57
[post_content] =>
[post_title] => Villa Porto Taverna
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-porto-taverna
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-22 21:50:20
[post_modified_gmt] => 2014-10-22 21:50:20
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1105
)
[2] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1127
[post_author] => 1
[post_date] => 2014-10-22 21:20:57
[post_date_gmt] => 2014-10-22 21:20:57
[post_content] =>
[post_title] => Villa Porto Taverna
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-porto-taverna
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-22 21:29:33
[post_modified_gmt] => 2014-10-22 21:29:33
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1127
)
[3] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1056
[post_author] => 1
[post_date] => 2014-10-21 21:13:49
[post_date_gmt] => 2014-10-21 21:13:49
[post_content] =>
[post_title] => Villa Verena
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-verena
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-22 20:05:54
[post_modified_gmt] => 2014-10-22 20:05:54
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1056
)
[4] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1071
[post_author] => 1
[post_date] => 2014-10-21 21:13:49
[post_date_gmt] => 2014-10-21 21:13:49
[post_content] =>
[post_title] => Villa Verena
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-verena
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-22 21:45:04
[post_modified_gmt] => 2014-10-22 21:45:04
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1071
)
[5] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1072
[post_author] => 1
[post_date] => 2014-10-21 21:13:49
[post_date_gmt] => 2014-10-21 21:13:49
[post_content] =>
[post_title] => Villa Verena
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-verena
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-22 21:39:56
[post_modified_gmt] => 2014-10-22 21:39:56
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1072
)
[6] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1017
[post_author] => 1
[post_date] => 2014-10-21 09:45:36
[post_date_gmt] => 2014-10-21 09:45:36
[post_content] =>
[post_title] => Villa Bella
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-bella
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-21 15:02:10
[post_modified_gmt] => 2014-10-21 15:02:10
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1017
)
[7] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1048
[post_author] => 1
[post_date] => 2014-10-21 09:45:36
[post_date_gmt] => 2014-10-21 09:45:36
[post_content] =>
[post_title] => Villa Bella
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-bella
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-21 20:55:33
[post_modified_gmt] => 2014-10-21 20:55:33
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1048
)
[8] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 1049
[post_author] => 1
[post_date] => 2014-10-21 09:45:36
[post_date_gmt] => 2014-10-21 09:45:36
[post_content] =>
[post_title] => Villa Bella
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-bella
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-21 20:58:50
[post_modified_gmt] => 2014-10-21 20:58:50
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 1049
)
[9] => Property Object
(
[_data:Property:private] => WP_Post Object
(
[ID] => 974
[post_author] => 1
[post_date] => 2014-10-20 14:29:56
[post_date_gmt] => 2014-10-20 14:29:56
[post_content] =>
[post_title] => Villa Golfo Aranci
[post_excerpt] =>
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => villa-golfo-aranci
[to_ping] =>
[pinged] =>
[post_modified] => 2014-10-20 15:25:19
[post_modified_gmt] => 2014-10-20 15:25:19
[post_content_filtered] =>
[post_parent] => 0
[guid] =>
[menu_order] => 0
[post_type] => properties
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
[meta:Property:private] => Array
(
)
[id:Property:private] => 974
)
)正如您在这里所看到的,相同的属性正在重复多次。
更新:
http://wpml.org/documentation/support/creating-multilingual-wordpress-themes/language-dependent-ids/
他们在文件中作了解释。但是,我们提取properties的方法是没有帮助的
发布于 2014-10-23 15:45:37
您可以使用icl_object_id(post_id, 'post_type', ICL_LANGUAGE_CODE)为当前语言中的每个属性获取post id。
例如,如果有这样简单的数组。
$properties = array(1128, 1105, 1127, 1056, 1071, 1072, 1017, 1048); // the ids for all the properties.
$post_ids = array();
foreach($properties as $property) {
$property_id = icl_object_id($property, 'properties', ICL_LANGUAGE_CODE); // the id for the current language
$post_ids[$property_id] = 1; // I set $property as the key to override same results
}
foreach($post_ids as $post_id=>$something) {
// and here you can use this post_id you can use get_post() or what you want...
}https://stackoverflow.com/questions/26528350
复制相似问题