使用WPML与房地产主题

时间:2014-10-23 12:41:32

标签: wordpress wpml

我正在使用WPML进行wordpress多语言。这是我用来获取特色房地产属性的代码:

<?php
$propMgr = new PropertiesManager();
$properties = $propMgr->getProperties('featured');

if(empty($properties)) {
    return;
}
?>

但是,此代码每三次返回特色属性,即我正在使用的所有三种语言。当选择英语时,我怎样才能让它返回英语等等。

更新

当我做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它的方式无法帮助

1 个答案:

答案 0 :(得分:0)

您可以使用icl_object_id(post_id, 'post_type', ICL_LANGUAGE_CODE)获取当前语言中每个媒体资源的帖子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...
}
相关问题