WordPress | Modify rewrite rule - wordpress

I have start maintaining a web site, that it is build from another person, and I like to modify the rewrite rules applied for a custom post type.
more specific, the custom post type is buidled with the following settings :
$args = array(
...
'rewrite' => array(
'slug' => 'myposttype',
'with_front' => false
),
....
)
register_post_type('myposttype', $args);
The permalink structure is the following:
Post name http://www.mysite.gr/sample-post/
but the url structure is the following:
http://www.mysite.gr/myposttype/my_post_slug/
how can I change it to
http://www.mysite.gr/my_post_slug/
Any idea please ?

Note: This is not a good idea as it may conflict with pages having the same slug.
Here is a tutorial on how to remove the post type name from the url.

Related

Custom post with custom URL

I have created a custom post, and I would like the URL to be:
example.com/directory/profile/slug/
With that in mind, this is a snap shot of how I have set it up:
$args = array(
...
'rewrite' => array( 'slug' => 'directory/profile' ),
'supports' => array( 'title', 'thumbnail' ),
);
I have created a corresponding file:
single-profile.php
If I remove the directory/ from the rewrite parameter, the new post shows up at this URL:
example.com/profile/slug/
I have looked at adding rewrite rules but either thats not the right approach or I am not doing that correctly.
Example:
add_rewrite_rule(
'^directory/profile/([^/]+)/?$',
'index.php?pagename=$matches[1]&post_type=profile',
'top'
);
What extra steps do I need to get this to work as intended?
An easy way to do it is: go to settings > permalinks, select Custom and set the value to /%postname%/.
No need for the rewrite rules.
Keep the post type slug as directory/profile.
Note that this will also change the default posts URLs to /postname. If you want to apply this change only for the post type, you can use this plugin, making the change above only for this post type.
Or do it on the code using the post_type_link hook, also works.

Custom URL structure for wordpress custom post type

I have two Custom Post type,
register_post_type( 'classes',
array(
.
.
'rewrite' => array( 'slug' => 'classes', 'with_front' => false )
)
);
register_post_type( 'lessons',
array(
.
.
'rewrite' => array( 'slug' => 'chapters', 'with_front' => false )
)
);
I have created a custom admin UI to manage (create/update/delete) this two post type, the lesson post type is design to be a child post type for classes post type. So everytime someone create a lesson, it requires a parent post from the list of post type classes.
Now I have a problem with the url structure,
the URL of the classes will be site.dev/classes/class-post-name
and the URL of the lesson will be site.dev/chapters/lesson-post-name this is also the URL I can i see on wp_posts table under guid column
How can I acheive a URL structure like below that will also be stored as guid?
site.dev/classes/parent-post-post-name/chapters/lesson-post-name
Parent Post From Another Post Type and a new URL structure will help in achieving the results. The lessons post type should be hierarchical and classes should be non-hierarchical. One thing is notable in the metabox that you don't need to save the metabox manually. WordPress itself checks for field name parent_id and saves it.

Change custom post type url/slug in wordpress?

i want to change my custom post url/slug from "property" to "project".
From this https://ayanaproperties.com/property/chelsea-creek-development-sw6-london/
To this https://ayanaproperties.com/project/chelsea-creek-development-sw6-london/
what method/plugin or any function to use?
You should search your theme for register_post_type function.
When you find it, make sure that it register your post type, and search for rewrite param. If it doesn't exists add it like the example below:
'rewrite' => array(
'slug' => 'developer',
),
Then make sure that you have updated your permalink structure.

wordpress permalinks for custom taxonomy

I'm using tribe events in wordpress and been struggling with the following problem:
I have events (custom post type) filtered by category (default taxonomy for this plugin).
I'm using "pretty permalinks settings" so my url looks like that:
[website.com]/events/category/Amsterdam/ (when my category is Amsterdam).
And now to the question:
I sub filtered my posts by another custom taxonomy called “event_type” (concert, pub …)
when I'm trying to get all the posts from Amsterdam that are a "concert" type, my url is:
[website.com]/events/category/amsterdam/?event_type=concert
on default permalink settings the url is:
[website.com]/index.php?tribe_events_cat=amsterdam&event_type=concert
How do I get WordPress to transform and to recognize my url as:
[website.com]/events/category/amsterdam/event_type/concert/
I know it has something to do with the rewrite_rules_array but could not manage to do so.
Any help would be very appreciated!
Thanx in advance.
While You register custom post type:
function people_init() {
// create a new taxonomy
register_taxonomy(
'people',
'post',
array(
'label' => __( 'People' ),
'rewrite' => array( 'slug' => 'person' ),
'capabilities' => array(
'assign_terms' => 'edit_guides',
'edit_terms' => 'publish_guides'
)
)
);
}
add_action( 'init', 'people_init' );
checkout the "rewrite" parameter. More You can check here:
http://codex.wordpress.org/Function_Reference/register_taxonomy
Also sometimes You need to flush permalink structure by going to permalink settings and clicking save (dont ask me why) ;).

WordPress Custom Post Types Rewrite

I have a custom post type using WordPress 3.0 that has the following rewrite rule:
'rewrite' => array( 'slug' => 'events', 'with_front' => false )
which gives the following: domain.com/events/my-awesome-event/
How can I pass some additional info into the rule, such as the date, I'm wanting to have the following rewrite: domain.com/events/2010/my-awesome-event/
Thanks.
Props to Benj in Using Dates in Custom post_type Permalinks - check out this article on custom post type permalinks

Resources