Hello,
I'm on the project with woocommerce where I use a custom field whose slug is "functional" and I would like to put all the values of this field in slug separated by a "-" and by putting the slug yoast at the end
Is that possible?
thank you
Hi, I'm not quite sure I understand. It sounds like you want to programmatically combine the values of some custom fields and do something with that string. Can you answer some more questions?
- Is this a repeating field?
- Is this field created in Types?
- What kind of field is this?
- Where do you want to store the computed value?
Hello Christian,
Indeed I want to retrieve the values of this field which was created with type but which is not a repeatable field.
in fact I would like all the values of this field to be put in the url in a way: "value1-value2-value2-value3/slug" or "value1-value-2-value3-slug".
For information, the slug is given by yoast.
Is that possible?
thank you in advance
I'm still not clear. Let's look at this one:
value1-value-2-value3-slug
Since it's not a repeating field, I assume value1 is on post 1, value2 is on post 2, and value 3 is on post 3. Where is "slug"? Is it on one of the posts 1 2 or 3? Or is it on some other post? How do you get this slug from Yoast, is there a shortcode?
You said you want to put these values in a URL. Which URL? Are you creating a link using a URL parameter like this?
<em><u>hidden link</u></em>
Or are you creating a custom page with the URL like this:
<em><u>hidden link</u></em>
Hello,Hello,
no each value is on the same post (a post can have several values).I would like to have an url this way:
hidden link
the slug is the wordpress slug normally.
Is that possible?
At the moment, the url of a post is hidden link and I would ideally like the url to be hidden link..../slug
Value 1, value 2... are values of custom field 'wpcf-fonctionnalites' of woocommerce post products
I don't know if I'm expressing myself correctly, unfortunately.
Okay I see, you would like to change a post's directory and URL structure based on some custom field values. That's not something Toolset can help you accomplish, unfortunately. Toolset's custom post URLs work within WordPress standard URL structures, which are .../custom-post-type-slug/post-slug. Adding custom field values in there would require custom URL manipulation code, that falls outside the scope of support we provide here in the forums. If you'd like to get professional assistance with this, we have a portal where you can connect with independent contractors: https://toolset.com/contractors.
and add custom field values at the slug is possible ?
No, you would need custom code to accomplish this type of custom URL structure. It will be quite difficult to maintain, so I don't have a cut-and-paste solution available for you.
Ok thank you Christian.
If it's quite difficult to maintain, it will not be relevant.
Yes because the post slug would change any time the custom fields change. It will be difficult to automate.
I totally understand.
But the values of the custom field will not change after creating the post.
Would that be possible?
It's possible with custom code. There is a hook called "save_post" in WordPress that you can use to manipulate post slugs when the post is created or updated. There are examples available here: https://codex.wordpress.org/Plugin_API/Action_Reference/save_post
ok and how manipulate value of the custom field ?
I'm not sure I understand. You haven't mentioned anything about manipulating the value of any custom field. You mentioned getting the value of a custom field and using that value in the slug of a post. To get a raw custom field value, you can use get_post_meta(). Types fields have a 'wpcf-' prefix in the database, so if you want to get the value of a field "test" for post 123, the code looks like this:
$value = get_post_meta( 123, 'wpcf-test', true );
https://developer.wordpress.org/reference/functions/get_post_meta/
To get a formatted value, use the Types Field API: https://toolset.com/documentation/customizing-sites-using-php/functions/
Hello Christian,
To summarize, I have products and a custom field "features" where the administrator can assign several values already defined.
I would like to inject these values into the slug of the product automatically so that it faces: ........./value1-value2-slug
Is that possible? I don't know if that's clear?