feat: project permalink using ID

This commit is contained in:
2025-09-16 10:01:26 -04:00
parent 28186c9141
commit cd2bfdfc0b
2 changed files with 25 additions and 4 deletions

View File

@@ -45,7 +45,7 @@ function ccat_project_register_post_type() {
'supports' => array( 'title', 'thumbnail', 'excerpt', 'revisions' ),
'has_archive' => false,
'rewrite' => array(
'slug' => 'projet',
'slug' => 'projet/%project_id%',
'with_front' => false,
),
'query_var' => true,
@@ -86,3 +86,18 @@ function ccat_project_post_updated_messages( $messages ) {
return $messages;
}
// Add custom rewrite rules for project ID permalinks
add_action( 'init', 'ccat_project_add_rewrite_rules' );
function ccat_project_add_rewrite_rules() {
add_rewrite_rule( '^projet/([0-9]+)/?$', 'index.php?post_type=project&p=$matches[1]', 'top' );
}
// Filter project permalinks to use ID instead of slug
add_filter( 'post_type_link', 'ccat_project_custom_permalink', 10, 2 );
function ccat_project_custom_permalink( $permalink, $post ) {
if ( get_post_type( $post ) === 'project' ) {
$permalink = home_url( "/projet/$post->ID/" );
}
return $permalink;
}

View File

@@ -299,6 +299,12 @@ type Address {
"""State or province abbreviation"""
stateShort: String
"""Street name"""
streetName: String
"""Street number"""
streetNumber: String
}
"""
@@ -9260,7 +9266,7 @@ interface HierarchicalTermNode implements DatabaseIdentifier & HierarchicalNode
}
"""The Location type"""
type Location implements ContentNode & DatabaseIdentifier & HierarchicalContentNode & HierarchicalNode & Node & NodeWithExcerpt & NodeWithFeaturedImage & NodeWithRevisions & NodeWithTemplate & NodeWithTitle & UniformResourceIdentifiable & WithAcfGroupPostLocation {
type Location implements ContentNode & DatabaseIdentifier & HierarchicalContentNode & HierarchicalNode & Node & NodeWithExcerpt & NodeWithFeaturedImage & NodeWithRevisions & NodeWithTemplate & NodeWithTitle & Previewable & UniformResourceIdentifiable & WithAcfGroupPostLocation {
"""
Returns ancestors of the node. Default ordered as lowest (closest to the child) to highest (closest to the root).
"""
@@ -9467,7 +9473,7 @@ type Location implements ContentNode & DatabaseIdentifier & HierarchicalContentN
password: String
"""Connection between the Location type and the Location type"""
preview: LocationToPreviewConnectionEdge @deprecated(reason: "The "Location" Type is not publicly queryable and does not support previews. This field will be removed in the future.")
preview: LocationToPreviewConnectionEdge
"""The database id of the preview node"""
previewRevisionDatabaseId: Int
@@ -9593,7 +9599,7 @@ type LocationToPreviewConnectionEdge implements Edge & LocationConnectionEdge &
cursor: String
"""The node of the connection, without the edges"""
node: Location! @deprecated(reason: "The "Location" Type is not publicly queryable and does not support previews. This field will be removed in the future.")
node: Location!
}
"""Connection between the Location type and the Location type"""