Rewriting WordPress URLs

The first important difference between your rewrite rule, and the ones that Pippin has provided is that all of his rewrite rules point to index.php. This is an absolute must, you won’t get it to work any other way, all requests must point to index.php with your query vars appended.

The second important thing to note is that a rewrite must query some type of WordPress object. Every request runs a main query, a page, a single post, a category, etc..

The simplest way to solve this is to let your admin user select a page as the search page, and then point your rewrite to that page with your extra query vars appended:

function tn_rewrite_urls() {
    add_rewrite_rule(
        'venue/([^/]+)/?',
        'index.php?pagename=SELECTED_PAGE&venueName=$matches[1]',
        'top'
    );
}
add_action( 'init', 'tn_rewrite_urls' );

function tn_query_vars( $query_vars ) {
    $query_vars[] = 'venueName';
    return $query_vars;
}
add_filter( 'query_vars', 'tn_query_vars' );

In this example, you would swap SELECTED_PAGE with whatever the chosen page slug is. Also, don’t forget to add your query var to the query vars array, and be sure to flush rewrites after new rules are added.

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