add_rewrite_endpoint() not working for custom post type archives
add_rewrite_endpoint() not working for custom post type archives
add_rewrite_endpoint() not working for custom post type archives
I used this to enable yearly and monthly archive for custom post type. Just drop in this code into your functions.php file. This will add your custom rule right on the top of the Rules array. NB – WordPress uses rules array to store rewrite rules. <?php function wpse22992_custom_post_rewrite( $rewrite_rules ) { $cpslug = ‘contest_recipe’; … Read more
They are totally differents: generate_rewrite_rules is an action hook and add_rewrite_rule is a function. That said, use add_rewrite_rule() if you want to define custom rewrite rules. Use generate_rewrite_rules to perform an action (from codex) “after all rewrite rules have been created”. That doesn’t mean that you can not add rewrite rules via generate_rewrite_rules, in fact … Read more
First of all use add_rewrite_rule() over messing directly with $wp_rewrite->rules if possible. The latter is a bit low-level. Regarding the ‘url not updating’ – this isn’t the job of the rewrite rules. These simply point urls to their content, but they don’t update the user’s address bar. The file that is responsible for this is … Read more
Have you tried: The main one: add_rewrite_rule( ‘region/([^/]+)/type/([^/]+)/?’, ‘index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]’, ‘top’ ); For pagination add_rewrite_rule( ‘region/([^/]+)/type/([^/]+)/page/([0-9]{1,})/?’, ‘index.php?taxonomy=region&term=$matches[1]&post_type=$matches[2]&paged=$matches[3]’, ‘top’ ); Out of curiousity, I replaced one of the ([^/]+) with the literal ‘type’ since that doesn’t seem to be a dynamic variable. If the pagination doesn’t work, try switching the order of when it’s declared, i.e. before … Read more
I believe you could just call the paged add_rewrite_url last so that it is checked first. Otherwise the paged version will never get any match, since the non-paged one will always match first. Should also work if you remove ‘top’ from your arguments. Also, check out this page for a nice way of debugging those … Read more
the flush_rewrite_rules() function will delete and regenerate the rewrite rules. you can also visit the permalinks settings page in admin and save, that triggers a flush as well.
I’ve just done a project where two Custom Post Types needed to share the same slug. The trick is to overwrite the query vars via the request filter. Let’s call the post types ‘foo’ and ‘bar’, and they will share slug ‘foo’. The following code is rough and from memory for example only. Salt to … Read more
Step 1, add the rewrite tags for custom event year and month query vars, then register the event post type with those tags in the slug argument of the rewrite argument: function wpa83531_register_event_post_type(){ add_rewrite_tag(‘%event_year%’,'(\d+)’); add_rewrite_tag(‘%event_month%’,'(.+)’); register_post_type( ‘event’, array( ‘public’ => true, ‘rewrite’ => array( ‘slug’ => ‘events/%event_year%/%event_month%’ ), ‘has_archive’ => false, ‘hierarchical’ => false, ‘supports’ … Read more
I found the solution on the Codex just after posting on the site and this is the code I was looking for: function my_htaccess_contents( $rules ) { $my_content = <<<EOD \n # BEGIN My Added Content # Protect wpconfig.php <Files wp-config.php> Order Allow,Deny Deny from all </Files> # END My Added Content\n EOD; return $my_content … Read more