AdvancedCustomFields / AdvancedCustomFields/acf
Using Taxonomy field in Gutenberg panel, does not update Post URL
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 945
- Forks
- 197
- PR merge metrics
- No merged PRs in 30d
Description
Describe the bug
When using the Taxonomy field to replace the core panel for assigning taxonomy terms, and the permalink includes the taxonomy term slug, on Publish the URLs to view the Post in Gutenberg are not updated.
To Reproduce
Steps to reproduce the behavior:
- Create a field group with Taxonomy field
- Update Permalink structure to include slug of assigned term from taxonomy used in Taxonomy field (
%{taxonomy}%) - Disable the core panel for assigning terms
- Add filter on
post_linkto replace the%{taxonomy}%with the assigned term's slug - Create a new Post, verifying core taxonomy panel is not available, and ACF panel with Taxonomy field is available
- Select a term in ACF Taxonomy field
- Publish the Post
- Notice the URL is not updated with the assigned term's slug
Expected behavior
Post's URL is updated with the slug of the assigned term immediately on Publish/Update.
Screenshots or Video
If applicable, add screenshots or video to help explain your problem.
Code
Disable core panel:
wp.data.dispatch( 'core/edit-post' ).removeEditorPanel( 'taxonomy-panel-{taxonomy}' );
Filter URL:
add_filter( 'post_link', static function ( string $permalink, \WP_Post $post, bool $leavename ): string {
if ( 'post' !== $post->post_type ) {
return $permalink;
}
if ( ! str_contains( $permalink, '%{taxonomy}%' ) ) {
return $permalink;
}
$types = get_the_terms( $post, '{taxonomy}' );
if ( empty( $types ) ) {
return $permalink;
}
$term = reset( $types );
return str_replace( "%{taxonomy}%", $term->slug, $permalink );
}, 10, 3 );
Version Information:
- WordPress Version 6.5.3
- PHP Version 8.2
- ACF PRO 6.3.0.1
- Brave Version 1.66.110 Chromium: 125.0.6422.60
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reproducing the issue in Gutenberg using the Taxonomy field, the disabled core taxonomy panel, the shown post_link filter, and a permalink containing the taxonomy placeholder. Compare the URL after Publish and Update; done means it immediately contains the selected term's slug.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, php
- Domain
- backend, web-dev
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100