url rewriting for most recent post

add_action( ‘init’, ‘ASHmostrecent_init’ ); function ASHmostrecent_init(){ add_rewrite_rule( ‘last/?$’, ‘index.php?post_type=post&posts_per_page=1′); } A query already pulls up posts starting from the latest to the oldest, so all you have to do is limit what’s returned by one. posts_per_page does this; limiting by one will give you the latest post. Edit the post_type accordingly.

URL rewriting must be activated manually for my plugin

Whenever I create a plugin that needs permalinks enabled i check on the plugin activation and if its not set i display a message for the user: // Add Check if permalinks are set on plugin activation register_activation_hook( __FILE__, ‘is_permalink_activate’ ); function is_permalink_activate() { //add notice if user needs to enable permalinks if (! get_option(‘permalink_structure’) … Read more

Custom query variable – get wordpress to redirect to nice permalink url

I figured out a solution myself. No javascript required, only another template function. URL building done manually. The idea is to use the hook ‘template_redirect’, check if the requested page is the corresponding store archive page, then check for $_REQUEST vars there and build a new URL. Finally redirect to this URL. function my_template_redirect() { … Read more

Image Attachment Url Rewrite

Ok so I found the answer. I used the code as per https://wordpress.stackexchange.com/a/56426/37472 and changed all references of ‘series’ to ‘gallery’. That added the required rewritre rule to parse a link like domain.com/landscapes/gallery/123/ to index.php?attachment_id=123. My assumption was that wordpress would display the default permalink that is generated by get_permalink() in the domain.com/landscapes/gallery/123/ format. It … Read more