How to trigger 404 for custom query var?

There is an action specifically for this: function my_parse_query( $wp_query ) { if ( $wp_query->get( ‘my_custom_var’ ) > 42 ) { $wp_query->set_404(); status_header( 404 ); } } add_action( ‘parse_query’, ‘my_parse_query’ ); That should load the 404.php template in your theme, if you have it. Otherwise, it will fall back to index.php. This will also trigger … Read more

How to enable hierarchical permalinks for hierarchical taxonomies

This is implemented in WordPress now as of 3.1. When you register your taxonomy, make sure to set rewrite hierarchical to true as well as the taxonomy itself: <?php register_taxonomy(‘genre’,array(‘book’), array( ‘hierarchical’ => true, // this makes it hierarchical in the UI ‘labels’ => $labels, ‘show_ui’ => true, ‘query_var’ => true, ‘rewrite’ => array( ‘hierarchical’ … Read more

Case-insensitive add_rewrite_rules in WordPress functions

As the answer below mentions, it is not possible to pass a flag to add_rewrite_rule(); however, it is possible to use an inline modifier. In your example, you would do this: $aNewRules = array(‘(?i)my-books/?$’ => ‘index.php?pagename=my-books’); (note the (?i) in the regular expression). The advantage of this approach is that your rewrite rules are much … Read more

add_query_vars and add_rewrite_rules

You can see in this answer how add_rewrite_rules is being used, I don’t think it applies to your case at all. What you need to do is to redirect urls generated from the search from (I’m assuming something like site.com/?s=term) to a pretty URL. This article do it http://www.wptavern.com/how-to-make-the-wordpress-search-url-pretty

WordPress Custom URL Rewrites

I do something similar with custom records called shops and their specific ID number. In my case I want http://example.com/shops/UNIDrecordthatsreallylong to load with the variable shop_unid being the UNID record. Here’s my working function: //Shop page rewrites function shop_rewrite() { add_rewrite_rule(‘^shops/([^/]*)/?’,’index.php?pagename=shops&shop_unid=$matches[1]’,’top’); add_rewrite_tag(‘%shop_unid%’,'([^&]+)’); } add_action(‘init’, ‘shop_rewrite’); Note that I used pagename instead of the post number. … Read more

Rewrite url for custom post type

this will not work: ‘en/index.php?post_type=vinos’ there is no en/index.php, it has to be: ‘index.php?post_type=vinos’ if you need to detect en in the path, add a query var, then set that query var in your rewrite: function wpa_query_vars( $qvars ) { $qvars[] = ‘wpa_lang’; return $qvars; } add_filter( ‘query_vars’, ‘wpa_query_vars’ ); then in your rewrite rule: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)