Making extra parameters optional

Two points: Your rule isn’t particularly specific. For numeric matches you should be specific about it and specify a) digits and b) how many digits. Year would be ([0-9]{4}), month/day would be ([0-9]{1,2}). You can’t do it with one rule. Add three separate rules instead. add_rewrite_rule( ‘whats-on/([0-9]{4})/?$’, ‘index.php?page_id=71&event_year=$matches[1]’,’top’); add_rewrite_rule( ‘whats-on/([0-9]{4})/([0-9]{1,2})/?$’, ‘index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]’,’top’); add_rewrite_rule( ‘whats-on/([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/?$’, ‘index.php?page_id=71&event_year=$matches[1]&event_month=$matches[2]&event_day=$matches[3]’,’top’);

How to change URL structure for pagination pages?

You may use the format argument of wp_link_pages function like this: <?php $args = array( ‘base’ => ‘%_%’, ‘format’ => ‘?page=%#%’, ‘total’ => 1, ‘current’ => 0, ‘show_all’ => False, ‘end_size’ => 1, ‘mid_size’ => 2, ‘prev_next’ => True, ‘prev_text’ => __(‘« Previous’), ‘next_text’ => __(‘Next »’), ‘type’ => ‘plain’, ‘add_args’ => False, ‘add_fragment’ => … Read more

Tricky URL rewrite with custom values in url

As I mentioned in your other question, you don’t want to be touching the .htaccess file, you need an internal rewrite. So, given the URL: http://mysite.com/image/wp_username/3digitnumber we need to add the following rule to handle it: // set up the rewrite rule function wpa73374_setup_rewrites(){ add_rewrite_rule( ‘image/([^/]+)/([0-9]+)/?$’, ‘index.php?pagename=custompage&iuser=$matches[1]&iname=$matches[2]’, ‘top’ ); } add_action( ‘init’, ‘wpa73374_setup_rewrites’ ); Note … Read more

Custom rewrite rules for feeds of custom queries (query_var query strings in URL)?

You can use add_rewrite_rule hooked to the init action, instead of using the generate_rewrite_rules filter (where it gets a bit low-level). But the actual problem with your rewrite rules is the regex in place. Here’s what it’d look like: function wtnerd_edition_specific_categories() { add_rewrite_rule( ‘(.+?)/channel/(.+?)/feed/(feed|rdf|rss|rss2|atom)/?$’, ‘index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]’, ‘top’ ); add_rewrite_rule( ‘(.+?)/channel/(.+?)/(feed|rdf|rss|rss2|atom)/?$’, ‘index.php?category_name=$matches[1]&channel=$matches[2]&feed=$matches[3]’, ‘top’ ); add_rewrite_rule( ‘(.+?)/channel/(.+?)/page/?([0-9]{1,})/?$’, ‘index.php?category_name=$matches[1]&channel=$matches[2]&paged=$matches[3]’, … Read more

External Rewrite Rules

Here’s a quick (hopefully error-free!) example of adding an internal rewrite and loading a plugin file to process those requests. This will give you access to the WordPress environment so you can use the database, etc.. The general steps are: add your rewrite and point it to index.php with your custom query vars appended register … Read more

Need to make a php file inside theme accessible via url

Ok here is a test working solution: <?php /* Plugin Name: wpse26719 Plugin URI: http://en.bainternet.info Description: Need to make a php file inside theme accessible via url Version: 1.0 Author: Bainternet Author URI: http://en.bainternet.info */ // Register a URL that will set this variable to true add_action(‘generate_rewrite_rules’, ‘wpse26719_rw’); function wpse26719_rw($wp_rewrite) { $newrules = array(); $new_rules[‘^adserver.js.php$’] … Read more

Create additional short URL with custom field and 301 redirect

The first step is the rewrite rule. I’ve also added a rewrite tag so the custom query var will be parsed. You can also use the query_vars filter for this instead. add_action( ‘init’, ‘tipp_rewrite_rule’ ); function tipp_rewrite_rule() { add_rewrite_tag( ‘%trick_nummer%’, ‘([a-zA-Z0-9]+)’ ); add_rewrite_rule( ‘^tipp([a-zA-Z0-9]+)?’, ‘index.php?trick_nummer=$matches[1]’, ‘top’ ); } The second step is to intercept these … Read more

Change the custom post type permalink

You can use rewrite arg in register_post_type. You can have custom post type name different then rewrite slug. For example here is the sample code with custom post type project and it shows pages with http://shaowtriger.com/brands/naim/ Notice rewrite in $args add_action( ‘init’, ‘codex_brand_init’ ); function codex_brand_init() { $labels = array( ‘name’ => _x( ‘Brands’, ‘post … Read more

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