我有一个名为restaurant
的自定义CPT,我需要使用WPML
创建不同语言的网址,例如:
http://example.com/restaurants/latvia/riga/restaurant-name
http://example.com/it/ristoranti/lettonia/riga/nome-ristorante
在主要语言中它起作用,完全没问题。
问题在于it
lang,如果我访问链接,我会得到404页面
如果我将var_dump
添加到$query
中的pre_get_posts
,我会得到:
object(WP_Query)[2049]
public 'query' =>
array (size=1)
'attachment' => string 'steiku-haoss' (length=12)
public 'query_vars' =>
array (size=53)
'attachment' => string 'steiku-haoss' (length=12)
'error' => string '' (length=0)
'm' => string '' (length=0)
'p' => int 0
'post_parent' => string '' (length=0)
'subpost' => string '' (length=0)
'subpost_id' => string '' (length=0)
'attachment_id' => int 0
'name' => string '' (length=0)
'static' => string '' (length=0)
'pagename' => string '' (length=0)
'page_id' => int 0
'second' => string '' (length=0)
'minute' => string '' (length=0)
'hour' => string '' (length=0)
'day' => int 0
'monthnum' => int 0
'year' => int 0
'w' => int 0
'category_name' => string '' (length=0)
'tag' => string '' (length=0)
'cat' => string '' (length=0)
'tag_id' => string '' (length=0)
'author' => string '' (length=0)
'author_name' => string '' (length=0)
'feed' => string '' (length=0)
'tb' => string '' (length=0)
'paged' => int 0
'meta_key' => string '' (length=0)
'meta_value' => string '' (length=0)
'preview' => string '' (length=0)
's' => string '' (length=0)
'sentence' => string '' (length=0)
'title' => string '' (length=0)
'fields' => string '' (length=0)
'menu_order' => string '' (length=0)
'embed' => string '' (length=0)
'category__in' =>
array (size=0)
empty
'category__not_in' =>
array (size=0)
empty
'category__and' =>
array (size=0)
empty
'post__in' =>
array (size=0)
empty
'post__not_in' =>
array (size=0)
empty
'post_name__in' =>
array (size=0)
empty
'tag__in' =>
array (size=0)
empty
'tag__not_in' =>
array (size=0)
empty
'tag__and' =>
array (size=0)
empty
'tag_slug__in' =>
array (size=0)
empty
'tag_slug__and' =>
array (size=0)
empty
'post_parent__in' =>
array (size=0)
empty
'post_parent__not_in' =>
array (size=0)
empty
'author__in' =>
array (size=0)
empty
'author__not_in' =>
array (size=0)
empty
'meta_query' =>
array (size=0)
empty
public 'tax_query' => null
public 'meta_query' => boolean false
public 'date_query' => boolean false
public 'post_count' => int 0
public 'current_post' => int -1
public 'in_the_loop' => boolean false
public 'comment_count' => int 0
public 'current_comment' => int -1
public 'found_posts' => int 0
public 'max_num_pages' => int 0
public 'max_num_comment_pages' => int 0
public 'is_single' => boolean true
public 'is_preview' => boolean false
public 'is_page' => boolean false
public 'is_archive' => boolean false
public 'is_date' => boolean false
public 'is_year' => boolean false
public 'is_month' => boolean false
public 'is_day' => boolean false
public 'is_time' => boolean false
public 'is_author' => boolean false
public 'is_category' => boolean false
public 'is_tag' => boolean false
public 'is_tax' => boolean false
public 'is_search' => boolean false
public 'is_feed' => boolean false
public 'is_comment_feed' => boolean false
public 'is_trackback' => boolean false
public 'is_home' => boolean false
public 'is_404' => boolean false
public 'is_embed' => boolean false
public 'is_paged' => boolean false
public 'is_admin' => boolean false
public 'is_attachment' => boolean true
public 'is_singular' => boolean true
public 'is_robots' => boolean false
public 'is_posts_page' => boolean false
public 'is_post_type_archive' => boolean false
private 'query_vars_hash' => string '5215071224e026852fe2fe893457f985' (length=32)
private 'query_vars_changed' => boolean false
public 'thumbnails_cached' => boolean false
private 'stopwords' => null
private 'compat_fields' =>
array (size=2)
0 => string 'query_vars_hash' (length=15)
1 => string 'query_vars_changed' (length=18)
private 'compat_methods' =>
array (size=2)
0 => string 'init_query_flags' (length=16)
1 => string 'parse_tax_query' (length=15)
正如您所见,它被查询为attachment
。
我还创建了一个自定义rewrite_rule
但是被忽略了,我也尝试对该值进行硬编码,但WP无论如何都会忽略它:
add_rewrite_rule($lang_code . '/' . $pt_translated . '/lettonia/riga/steiku-haoss/?$',
'index.php?&post_type=' . $pt_original . '&mlt_location=lettonia&name=$matches[3]', 'top');
这是我的reg_exp:it/ristoranti/.+?/[^/]+/([^/]+)/?$
这怎么可能?
修改
我使用WPML