Skip Navigation

[Resolved] Custom field and sug

This support ticket is created 5 years, 7 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 20 replies, has 2 voices.

Last updated by stephaneB-5 5 years, 6 months ago.

Assisted by: Christian Cox.

Author
Posts
#1270761

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

#1270881

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?

#1271413

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

#1271775

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>
#1272297

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.

#1272677

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.

#1272707

and add custom field values at the slug is possible ?

#1272753

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.

#1272833

Ok thank you Christian.
If it's quite difficult to maintain, it will not be relevant.

#1272837

Yes because the post slug would change any time the custom fields change. It will be difficult to automate.

#1273487

I totally understand.
But the values of the custom field will not change after creating the post.
Would that be possible?

#1273555

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

#1275589

ok and how manipulate value of the custom field ?

#1275783

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/

#1276445

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?