Hot answers tagged

7

Extending @Howdy_McGee answer. First you can not have two post with the same slug (Not title) which explained already in other answers. Second you can have page and post with same slug. But you will be able to access only page when your permalink structure is /%postname%/. And there is debate going on this ticket#13459 about this issue/feature since 6 ...


6

As far as I know, you can't have two posts with the same slug. Whenever you attempt to change a post slug to something that already exists, WordPress will append -2 to the newest slug to differentiate the two. So, if you already have a post with the slug of test and attempt to create another post with the same slug, WordPress will instead give that slug test-...


5

It is not a bug. As @LuisSanz pointed out, post_type_link isn't used for the built-in post post type. It is used for custom post types only. Skim through get_permalink() function, you will find out that WordPress doesn't use post_type_link filter but uses post_link filter. It means that you're using wrong filter. Then, change post_type_link to post_link ...


5

Suppose articles is slug of the category. 1. Add a custom rewrite rule: add_action('init', function() { add_rewrite_rule('^articles/([^/]+)/?$', 'index.php?name=$matches[1]', 'top'); }, 10, 0); 2. Filter the post link: add_filter('post_link', function($post_link, $post, $leave_name = false, $sample = false) { if ( has_category('articles', $post) ...


4

Since it is a performance question, you might be able to avoid using meta keys at all by storing/getting that data another way and not having to set a separate meta field to match with... a. You could get the year from the published $post->post_date... So that when doing the query just use the date argument: $args = array( 'post_type' => $...


3

If you'd like to keep your slugs for SEO, then you'll want to define a new rewrite tag and leave the default behavior for post slugs. If you'd like a unique id, then instead of looking up possible duplicates, why not just re-use the post ID which is guaranteed to be unique given a MySQL primary index – you can convert it to a base36 number if you want it to ...


3

You can accomplish this with add_rewrite_rule(). I personally like to show this example in a class to make it copy/paste ready. You could throw this in a plugin or functions.php -- some place that loads this code before query_vars, parse_request and init. The goal is to add rewrite rules, make sure you can add custom properties to the main query, then ...


2

Yes this is correct. You can choose custom permalink the way you want. But it is limited to these official tags only. And %post_id% is one of those tags so you can use it. Just a note here you need to end the custom structure with post ID or name as codex says Make sure to end your structure with either %post_id% or %postname% (e.g. /%year%/%monthnum%...


2

Whenever a post is saved WP calls the wp_unique_post_slug function that will compute a unique slug, based on the post title and a suffix like -2 if another post has the same title. However, you can filter this function, to generate your own slug. So, if you want to mess things up, that's possible.


2

I found solution! A Monkeyman Rewrite Analyzur plugin was very helpful: https://wordpress.org/plugins/monkeyman-rewrite-analyzer/ So now, I have such working urls... single.php: /magazine-name/issue-year/issue/article-name archive.php: /magazine-name/issue-year/issue /magazine-name/issue-year /magazine-name On a custom post editor page in wp-admin I ...


2

You're using the same slug for both your videos custom post type and video_type taxonomy. Then, when querying post, WordPress don't know what to select from database. Change your videos post type to video or something differs from videos taxonomy slug will solve your problem.


1

Ok, i have some basic ideas. You can install a plugin called Redirection. And after that, you can make like and redirect to some other pages with you own data. but URL will change as the person redirect to the other specific page. Now if you want to them to land on the specific page... you need to make the folder into server directory under the main site ...


1

I found an exact solution I'm looking for. function my_comment_link_filter( $link ) { $link = str_replace( get_permalink() , $custom_permalink , $link ); return $link; }; add_filter( 'get_comment_link', 'my_comment_link_filter' ); It does exactly what I am looking for: It replaces the Page Permalink with the dynamic permalinks when I call the ...


1

Additionally, if the CPT has taxonomies associated with it, I've successfully used the following code to rewrite those as well: /** * Set 'with_front' to false for the 'portfolio_category' post taxonomy. */ add_filter( 'register_taxonomy_args', function( $args, $taxonomy ) { if( 'portfolio_category' === $taxonomy && is_array( $args ) )...



Only top voted, non community-wiki answers of a minimum length are eligible