2
votes

I had to create a custom post type, let's call it 'trucks'. The link to the archive of the posts looks like that: http://example.com/wpdirectory/?post_type=trucks I want it to look like that: http://example.com/wpdirectory/trucks without the '?post_type=' query. How can I affect it?

2

2 Answers

3
votes

I found out that it can be specified directly when registering new post type using register_post_type: use the argument 'has_archive' => 'your-desired-archive-permalink' in my case: 'has_archive' => 'trucks'

1
votes

Try using the add_rewrite_rule() function is your functions.php file. Try this:

add_action( 'init', 'rewritePostType' );
function rewritePostType(){
    add_rewrite_rule('^wpdirectory/([^/]*)/?','index.php?post_type=$matches[1]','top');
    add_rewrite_tag('%post_type%','([^&]+)');
}

Otherwise you can overwrite the permastructures in Settings -> Permalinks in Wordpress and hard code it in.