Note that there are some explanatory texts on larger screens.

plurals
  1. PONegating certain words from a custom rewrite expression?
    text
    copied!<p>I have a WP page named Book (/book/) which displays a book in various languages. The language and chapter variables are passed as query variables. So the URL structure looks like:</p> <p>/book/english/ (This displays a list of chapters in English) /book/english/foreword/ (This displays the Foreword of the book in English)</p> <p>Here is what I have come up with:</p> <pre><code>add_action('init', 'book_init'); add_filter('rewrite_rules_array', 'book_rewrite_rules_array'); add_filter('query_vars', 'book_query_vars'); function book_init() { global $wp_rewrite; $wp_rewrite-&gt;flush_rules(); } function book_rewrite_rules_array($rewrite_rules) { global $wp_rewrite; $custom['(book)/(.+)/(.+)$'] = 'index.php?pagename=$matches[1]&amp;book_language=$matches[2]&amp;book_chapter=$matches[3]'; $custom['(book)/(.+)$'] = 'index.php?pagename=$matches[1]&amp;book_language=$matches[2]'; return $custom + $rewrite_rules; } function book_query_vars($query) { array_push($query, 'book_language', 'book_chapter'); return $query; } </code></pre> <p>Everything is working but the problem is that, the rewrite rules I have added are also catching /book/feed/ which I don't want. So I am looking for an expression which would negate feed from '(book)/(.+)/(.+)$' and '(book)/(.+)$'</p> <p>Also I want to know, if assume the query variables supplied are invalid, which filter should I use to check this in and how can I stop WP from continuing and instead make it send a 404 error and have it show the 404 page?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload