Support

Account

Home Forums General Issues How to add field value to permalink?

Solving

How to add field value to permalink?

  • I have a custom field called “Course ID”.

    I have Woocommerce installed. In permalinks, under product permalinks, I have “/courses/%product_cat%”.

    I was wondering if it was possible to do something like “/courses/%product_cat%-%course_id%” or some way to add the course ID to the permalink.

  • It would give you 404 Error.

  • So there is no way to use ACF to add the value of a field to a page’s slug?

  • First you would need to figure out how to change the output of the link wherever WC is outputting it. Then you’d need to alter the WP rewrite rules for your site, especially since you are talking about altering a taxonomy term url. All could be possible with a large amount of work.

    Alternately, you could create an acf/save_post filter, see if what is being saved is a term in your taxonomy and then alter the term slug every time that the term is saved. Also a possible solution and more likely that the first one. Still a little complicated and I don’t know the exact details of getting it done.

  • Can you explain in very detail what you need to make ?
    Some hidden pay content ? Booking ?

  • I’m using woocommerce to set up courses.

    The courses available are for Grade 11 and Grade 12 students.

    English, for example, is part of both categories and looks like this:

    /grade-11/english
    /grade-12/english-2

    I’m trying to figure out a way to deal with this, I was thinking, because I already have a field that gets the course’s code, that I could use acf to modify the url to look like this:

    /grade-11/english-eng3u
    /grade-12/english-eng4u

    I could do this manually in the post’s slug, but I was thinking it would be neat if it were dynamic somehow.

  • Still dont get it.
    It looks like perfect job for Terms (taxonomy terms). You can use ACF for other manipulation(s), Therms select field, etc…

    You dont have to worry about permalinks when working with Terms.

  • If you see my OP, I should remove the /%product_cat% and use ACF to create terms that’ll be added to the permalink?

  • No.
    You cannot make permalinks like this and mix “/“, “” without heavy PHP magic.

    /grade-11/english to /grade-11/english-eng3u. Your field value (all of them) would need to have this sign “-“.

    You dont have so many language courses ? Even theoretically it they are in hundreds WordPress now manages Terms well. As long you dont use to many Select (dropdown) options Terms on shared hosting.

    Do it like this:

    – “grade 11” = (you use WooCommerce) Products main Category/Taxonomy/Term.
    – “english” = subcategory/Term of “grade11” main category.
    – “eng3u” = sub category/Term of “english” subcategory.

    Just simple nested categories and Terms. This is very reusable everywhere in WordPress for future website building, not like using fields. And Permalinks are generated naturally, no tweaks needed.

  • Hello @darrenbachan .

    You can use any custom post field generated by ACF plugin in URL permalink structure thanks to the plugin:
    https://github.com/athlan/wordpress-custom-fields-permalink-plugin/

    Moreover, you can create dynamic values based on that fields:
    https://github.com/athlan/wordpress-custom-fields-permalink-plugin/wiki/ACF-plugin-support

    Cheers,
    Athlan.

Viewing 10 posts - 1 through 10 (of 10 total)

The topic ‘How to add field value to permalink?’ is closed to new replies.