AdvancedCustomFields / AdvancedCustomFields/acf

Using Taxonomy field in Gutenberg panel, does not update Post URL

Open
#924 0 comments 0 reactions 0 assignees View on GitHub

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:

  1. Create a field group with Taxonomy field
  2. Update Permalink structure to include slug of assigned term from taxonomy used in Taxonomy field (%{taxonomy}%)
  3. Disable the core panel for assigning terms
  4. Add filter on post_link to replace the %{taxonomy}% with the assigned term's slug
  5. Create a new Post, verifying core taxonomy panel is not available, and ACF panel with Taxonomy field is available
  6. Select a term in ACF Taxonomy field
  7. Publish the Post
  8. 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

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.