Skip Navigation

[Resolved] Types field for choosing a post or image id

This thread is resolved. Here is a description of the problem and solution.

Problem:
How to add your own custom field type

Solution:
If you navigate to following path:

Plugins/types/embedded/includes/examples/google_map.php

This is the example how to add simple Google Maps field type. Could you please use it as a reference. Using above example you can create your own types custom field type.

Relevant Documentation:
https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/

This support ticket is created 8 years, 1 month 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by entwicklung 8 years, 1 month ago.

Assisted by: Minesh.

Author
Posts
#377116

Hello,

I`m using an image field on a custom post in Types. But I don`t want to get the URL of the image, but the id of the image post.

I read here https://toolset.com/forums/topic/how-to-get-id-of-image/ that this is possible by querying the id from the URL using the GUID. In my opinion, this is a dodgy way of doing this:
I can not rely on the GUID and the image URL to stay the same. The image url could have changed by domain changes, using https instead of http or plugins like hidden link or hidden link.

So my questions are:
1) Is an image/file field planned, which saves the id instead of the URL?
2) Is it possible to write my own custom fields for Types plugin? This would be a great way, and I could use types for everything.

A bit of background info: I`m trying to get rid of advanced custom fields, because it is not fully WPML compatible and using it combined with types causes some usability problems. But the Types field api does not give me the full option palette what ACF does.

Thank you!

#377168

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

So my questions are:
1) Is an image/file field planned, which saves the id instead of the URL?
=> This feature request is already been escalated to our developers and you will see its implemented in near future release. However I do not have any ETA on this.

2) Is it possible to write my own custom fields for Types plugin? This would be a great way, and I could use types for everything.
=> For now, you can use custom code.

see this related ticket:
https://toolset.com/forums/topic/get-id-of-attachment/

#377171

Hello Minish,

thank you.

Please give me a better answer to question 2:
a) This is not an answer to my question
b) I linked the ticket you pointed to in my post already. With an explanation why I think that this is the wrong way of doing this.

#377178

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

a) This is not an answer to my question
=> Please see following documentation:
https://toolset.com/documentation/customizing-sites-using-php/functions/#image

As you can see, with image field we do not have such attribute which will return you the ID of image. But as I said, its already in implementation and with our developer's to do's list and they will soon implemented it and it will be officially made available in near future release so that:
you can fetch:
- image file name
- or image filename with link,
- or image title
- or image title with link
- or image id

b) I linked the ticket you pointed to in my post already. With an explanation why I think that this is the wrong way of doing this.
=> Yes - you are right as well. Types used to store custom fields values to "post_meta" table.

so you may try with post meta.

$images = get_post_meta($post->ID, 'wpcf-gallery-images', false);

$images will have the complete data about post meta ID. post_id, post meta value. You can customize your code as you want.

I hope above information will help you.

#377180

Hi Minesh

thank you, it`s good to hear that this will be possible in the future.

But my question was:
2) Is it possible to write my own custom fields for Types plugin?

So I would like to write a field, define how the form looks like and what the output will be. For example based on the number field or something.

#377190

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

If you navigate to:
=> Plugins/types/embedded/includes/examples/google_map.php

This is the example how to add simple Google Maps field type. Could you please use it as a reference. Using above example you can create your own types custom field type.

Even you can convert non-types fields to types field.
https://toolset.com/faq/how-do-i-convert-existing-custom-types-and-fields-to-types-control/

#377200

Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.