Articles of permalinks

Programmatically adding posts

I’m about to create parser which would be inserting new custom posts. So, it’s pretty simple global $user_ID; $new_post = array( ‘post_title’ => ‘My New Post’, ‘post_content’ => ‘Lorem ipsum dolor sit amet…’, ‘post_status’ => ‘publish’, ‘post_date’ => date(‘Y-m-d H:i:s’), ‘post_author’ => $user_ID, ‘post_type’ => ‘post’, ‘post_category’ => array(0) ); $post_id = wp_insert_post($new_post); But i […]

How can a guest view the “Pending Review” Post?

When a user creates a new post it will have “pending” status. So I want the visitor (guest – not logged user) to be able to view “Pending” posts and vote it to “Publish” if enough “X Votes”. Google bot can also crawl “Pending” Posts. I want to use permalink for “Pending” Post. How can […]

custom post type default permalink

Is it possible to use the permalink structure defined in the WordPress settings panel for custom post types? And if so, how do I do that? I currently have: function add_posts_two() { $labels = array( ‘name’ => ‘Poststwo’, ‘singular_name’ => ‘posttwo’, ‘add_new’ => __(‘New Posttwo’), ‘add_new_item’ => __(‘New Posttwo’), ‘edit_item’ => __(‘Edit Posttwo’), ‘new_item’ => […]

nginx – permalinks with .php in url not working

I’m moving a site from an Apache server to a nginx server. A lot of the pages have a .php extension at the end of the permalink. Trying to view those pages results in a nginx 404 Not Found. However those pages worked fine on Apache. Here is the server block config for the site: […]

Change of permalink structure – redirects in htaccess breaks the archive links

When I started with my blog, the permalinks and following structure: http://<domain>/%year%/%monthnum%/%day%/%postname%/ Some time ago, I changed the permalink structure to “http://<domain>/%postname%/” only. In order to tackle the external links to the old permalink structure, I added the following line in my htaccess-file: RedirectMatch 301 /([0-9]+)/([0-9]+)/([0-9]+)/(.*)$ http://<domain>/$4 Now the problem is that the redirect line […]

Different permalink structure per category

Just for curiosity, is it possible to have a different permalink scheme for different templates or categories? For example, for post “XYZ leach review” in category pets/dogs to have “mysite.com/reviews/pets/dogs/xyz_leach_review.php” and then any post in another category to be “mysite.com/justthecastegory/the_post_name.php”?

how to flush custom author rewrite rule

So, I’ve created custom AUTHOR url like domain.tld/user-nicename, and i have now links like domain.tld/john-doe. My functions.php is // AUTHOR add_filter(‘author_rewrite_rules’, ‘no_author_base_rewrite_rules’); function no_author_base_rewrite_rules( $author_rewrite ) { global $wpdb; $author_rewrite = array(); $authors = $wpdb->get_results(“SELECT user_nicename AS nicename from $wpdb->users”); foreach($authors as $author) { $author_rewrite[“({$author->nicename})/?$”] = ‘index.php? author_name=$matches[1]’; } return $author_rewrite; } if( !is_admin() ) […]

Custom post type permalinks breaking due to 3.1 bug fix

So I just updated a site to 3.1 that uses several custom post types. When I had made the site I had not noticed at the time the $post_type parameter for register_post_type has to be in all lowercase letters! ( it was not well written in the codex but now it is bold). http://codex.wordpress.org/Function_Reference/register_post_type#Parameters My […]

How to hook into permalink when publishing-saving post?

I want to know how I can change the structure of the permalink to my desired one before saving or publishing my post in WordPress? For instance, when I add the title like the wordpress blog in my post I get the permalink structure similar to the below: http://localhost/2015/09/10/the-wordpress-blog/ I want to change it to […]

How to generate random numeric slugs for a custom post type?

I have this PHP code to generate a random numeric string: function generateRandomString($length = 12) { global $generatedStrings; $characters = ‘0123456789’; $randomString = ”; for ($i = 0; $i < $length; $i++) { $randomString .= $characters[rand(0, strlen($characters) – 1)]; } if (isset($generatedStrings[$randomString])) { $randomString = generateRandomString($length); } $generatedStrings[$randomString] = $randomString; return $randomString; } $generatedStrings = […]