Add .html (dot HTML) extension to custom post types

This seem to work: Create the rewrite rules like post-type/post-name.html. You can use arrays to create the rules for just some set of post types instead of doing it for all of them. add_action( ‘rewrite_rules_array’, ‘rewrite_rules’ ); function rewrite_rules( $rules ) { $new_rules = array(); foreach ( get_post_types() as $t ) $new_rules[ $t . ‘/([^/]+)\.html$’ … Read more

Permalink format: singular or plural

There’s a simple rule that I follow (it’s hard to explain, so I’ll give examples): http://example.com/categories/ <– This plural form should mean that the page shows a list of all the categories in use on your site. Similarly, if it’s “authors” (as in http://example.com/authors/), I’d expect the page to show a list (with or without … Read more

Remove custom post type slug from URL

That’s how you can do first part of the job – get rid o CPT slug in post link (eg. news post type). function df_custom_post_type_link( $post_link, $id = 0 ) { $post = get_post($id); if ( is_wp_error($post) || ‘news’ != $post->post_type || empty($post->post_name) ) return $post_link; return home_url(user_trailingslashit( “$post->post_name” )); } add_filter( ‘post_type_link’, ‘df_custom_post_type_link’ , … Read more

Understanding add_rewrite_rule

A basic rule that would work for your example: function wpd_foo_rewrite_rule() { add_rewrite_rule( ‘^foo/([^/]*)/?’, ‘index.php?pagename=$matches[1]&param=foo’, ‘top’ ); } add_action( ‘init’, ‘wpd_foo_rewrite_rule’ ); This takes whatever comes after foo/ and sets that as pagename for the query, and then param gets the static value foo. If you need different URL patterns, you’ll need extra rules for … Read more

Passing and retrieving query vars in wordpress

I’m almost sure that author is built-in, so use something like author_more. You will need to add that var to query_vars first. Example: // add `author_more` to query vars add_filter( ‘init’, ‘add_author_more_query_var’ ); function add_author_more_query_var() { global $wp; $wp->add_query_var( ‘author_more’ ); } Then on your more-author-posts.php template call it like this: if ( get_query_var( ‘author_more’ … Read more

How to rewrite URI of custom post type?

This is what I use to rewrite custom post type URLs with the post ID. You need a rewrite rule to translate URL requests, as well as a filter on post_type_link to return the correct URLs for any calls to get_post_permalink(): add_filter(‘post_type_link’, ‘wpse33551_post_type_link’, 1, 3); function wpse33551_post_type_link( $link, $post = 0 ){ if ( $post->post_type … Read more

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