博文

目前显示的是 二月, 2017的博文

[WordPress]Oops, customized query vars make front page missing

There is a very strange thing which may be a bug but not fixed yet in WordPress -- If you add a customized query var, it will make the WordPress lost the static front page and directly point to the post river. (As discussed in https://core.trac.wordpress.org/ticket/25143#comment:36 ) For example, if our static front page is http://www.example.com/ and we add following code to add a query var named 'lang' hoping that we could get 'lang' from the structure of http://www.example.com/%lang% function add_custom_page_variables ( $ public_query_vars ) {         $ public_query_vars [] = ' lang ';         return $ public_query_vars ;     } add_filter ( ' query_vars ', array ( $ this , ' add_custom_page_variables ' ) ) ; It doesn't work. get_query_var will return null and what is worse, the front page will lost if we use http://www.example.com/en. Actually, current parse_query will check $_query after it thinks it is a home pa

[WordPress] About the URL autocompletion function in WordPress

There is an unimpressive URL autocompletion function in WordPress which a lot of the users or developers may not know. This function can find the most similar URL even if the URL input is not exactly right. For example: there is a permalink http://www.example.com/testpost If you mistakenly input http://www.example.com/testp, the WordPress can still help you find the testpost. This sounds nice. But it can cause some problems. For example, I want to add a rewrite rule to make http://www.example.com/en point to http://www.example.com/?lang=en. This autocompletion function will still try to find something similar to 'en' instead of giving me the page of http://www.example.com directly. So we have to turn off this function. Here is the solution: add_action ( ' redirect_canonical ', ' __return_false ' ) ; After adding this action, this autocompletion function will be turned off and the rewrite rules will successfully work.

[WordPress API] About the 'count' field of get_terms function

get_terms is a very common function in WordPress. Here is the definition: get_terms(  array|string   $args  =  array() ,   array   $deprecated  =  ''  ) For example: $res = get_terms(term->taxonomy, array('parent' => term->id, 'hide_empty' => false)); var_dump($res); The WordPress will print something like this: array (size=5) 0 => object ( WP_Term )[ 4319 ] public 'term_id' => int 15 public 'name' => string 'Copenhagen S' (length=12) public 'slug' => string 'copenhagen-s' (length=12) public 'term_group' => int 0 public 'term_taxonomy_id' => int 15 public 'taxonomy' => string 'property_city' (length=13) public 'description' => string '' (length=0) public 'parent' => int 37 public 'count' => int 3 public