add_rewrite_rule query_var not being set

In response to yivi’s inquiry, So I was able to solve the problem by putting the hardcode portion of the redirect string first as shown here: add_rewrite_rule( “{$list_view_template}/(.*)?”, ‘index.php?mlscrit=/list-view/$matches[1]&pagename=” . $list_view_template, “top’ ); Thanks!

Can someone explain the function of the third parameter of “add_rewrite_tag”

The third parameter tells WordPress what query variable(s) to use/match. We can query our WordPress database with those public query variables, via requests like example.com/?foo1=bar1&foo2=bar2 but we usually want to rewrite it to something more pretty, like example.com/bar1/bar2/. In the Codex there’s a list of the default available public query variables: attachment attachment_id author author_name … Read more

add_rewrite_rules prefix everything

Have you ever consider to use rewrire_rules_array filter to alter $rewrite_rules? /** * Example of Changing All Rewrite Rules * * @param array $rewrite_rules The compiled array of rewrite rules. * @return array The compiled array of rewrite rules (altered). */ function wpse_263624_rewrite_rules_example( $rewrite_rules ) { $prefixes = array( ‘otro’, ‘esto’ ); $prefix_regexp = ‘(‘ … Read more

Rewrite rules and query for virtual page

You can create a posts archive by just setting post_type=post in your rewrite rule: function custom_archive_rule() { add_rewrite_rule( ‘custom-archive/?’, ‘index.php?post_type=post’, ‘top’ ); } add_action( ‘init’, ‘custom_archive_rule’ ); WordPress will identify this as is_home, so you’ll have to target it in pre_get_posts by the existence of your extra query variables. function custom_arcive_tax( $query ) { if … Read more

add_feed and flush_rewrite_rules

You have to check the existing rewrite rules before you run a flush. If your feed name is test, they are stored under the keys ‘feed/(feed|rdf|rss|rss2|atom|test)/?$’ and ‘(feed|rdf|rss|rss2|atom|test)/?$’. So this should do the trick: add_action( ‘init’, function() { $name=”test”; $registered = FALSE; add_feed( $name, ‘test_feed’ ); $rules = get_option( ‘rewrite_rules’ ); $feeds = array_keys( $rules, … Read more