Custom post type yearly/ monthly archive permalinks

Here’s an example using add_rewrite_rule to handle years and months for a custom post type where news is the slug. Visit the Settings > Permalinks page in admin to flush rewrite rules after this is added. You could also put this in a plugin and flush rewrite rules on plugin activation. function wpa83797_news_rewrite_rules(){ add_rewrite_rule( ‘news/([0-9]{4})/([0-9]{1,2})/?$’, … Read more

Adding rewrite endpoint breaks static front page

Maybe I did not get this very well, but if you need to just remove ‘foo’ from query vars would not be much more simple to use the ‘request’ filter and remove the var from there? Code needed: add_filter(‘request’, function($query_vars) { return array_diff_key($query_vars, array(‘foo’=>”)); }); It: runs on main query only remove the var for … Read more

Using $_GET variables in the URL?

Try adding the variable to the WordPress’ array of ‘recognised query variables’… add_filter(‘query_vars’, ‘my_register_query_vars’ ); function my_register_query_vars( $qvars ){ //Add query variable to $qvars array $qvars[] = ‘my_error’; return $qvars; } Then the value of ‘my_error’ can be found via get_query_var(‘my_error’). (See Codex) EDIT From Otto’s comment, it’s better to do: add_action(‘init’,’add_my_error’); function add_my_error() { … Read more

Custom post types – Use post_id in permalink structure

@Bainternet – your answer didn’t fully work but I did some more searching and was able to piece this filter together that did work: add_filter(‘post_type_link’, ‘custom_event_permalink’, 1, 3); function custom_event_permalink($post_link, $id = 0, $leavename) { if ( strpos(‘%event_id%’, $post_link) === ‘FALSE’ ) { return $post_link; } $post = &get_post($id); if ( is_wp_error($post) || $post->post_type != … Read more