1

I am trying to update the URL structure for posts within a custom post type. I would like the url to use the taxonomy slug from the "resource-topic" taxonomy, and not the custom post type key.

Currently the custom post type key is used in the permalink.

For example:

  • instead of /resource-new/[blog-title]
  • I want it to be /press-releases/[blog-title]

We are using the advanced custom fields plugin > custom post type and taxonomies.

The custom post type is called Resources (resource-new).

I have attempted to modify this using the ACF advanced settings > URLS, but this does not work.

Thank you

enter image description here

enter image description here

enter image description here

    2 Answers 2

    0

    I'm having a similar problem. No matter what I do, I can't get the custom taxonomies I create in ACF to be part of the custom post type's permalink; it always remains /custom_post_type_slug/post_title

      0

      I found a solution that worked for me. The custom taxonomy name I used was "resource-topic" and the post type "resource_new". This function rewrites the URLs and uses the custom taxonomy slug. If you replace these with what you named each and add the function to the functions file it should work for you.

      If you have multiple custom post types that need to be rewritten this code would need to be amended.

      function custom_rewrite_rules() { $resource_topics = get_terms([ 'taxonomy' => 'resource-topic', 'hide_empty' => false, 'fields' => 'slugs', ]); if (!empty($resource_topics) && !is_wp_error($resource_topics)) { foreach ($resource_topics as $topic_slug) { add_rewrite_rule("^{$topic_slug}/([^/]+)/?$", 'index.php?resource-topic=' . $topic_slug . '&resource_new=$matches[1]', 'top'); } } } add_action('init', 'custom_rewrite_rules'); 

        Start asking to get answers

        Find the answer to your question by asking.

        Ask question

        Explore related questions

        See similar questions with these tags.