Skip Navigation

[Resuelto] Retrieving Custom image field ID

This support ticket is created hace 4 años, 11 meses. 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
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 6 respuestas, has 2 mensajes.

Last updated by lucaso hace 4 años, 10 meses.

Assisted by: Christian Cox.

Autor
Mensajes
#1267109

I am trying to:
Im trying to get the ID of a custom field image to use inside a shortcode, I need
Link to a page where the issue can be seen:

I expected to see:
A shortcode that outputs the numerical ID of the uploaded image, so that can be used in a shortcode,
Instead, I got:
I can get this with the featured image shortocde
[wpv-post-featured-image output="id"] this works fine
but when inserting the image from the custom field I dont get an option to insert ID, I understand this can be achieved via shortcode, can you help

#1267129

Here's some sample code you can use as a reference:

global $wpdb, $post;
$slug = 'book-single-img-1';
$url = get_post_meta( $post->ID, 'wpcf-'.$slug, true );
$id = $wpdb->get_var( $wpdb->prepare ("SELECT ID FROM $wpdb->posts WHERE guid=%s ORDER BY `ID` DESC", $url ) );
// $id = numeric ID of the image
#1268119

Hello, thanks for your quick reply, but im afraid I need a bit of help,

my custom field name is "imagen"
Does this go in the function.php file?

global $wpdb, $post;
$slug = 'imagen';
$url = get_post_meta( $post->ID, 'wpcf-'.$slug, true );
$id = $wpdb->get_var( $wpdb->prepare ("SELECT ID FROM $wpdb->posts WHERE guid=%s ORDER BY `ID` DESC", $url ) );
// $id = numeric ID of the image

how do I implement the shortcode?

will it give just one number? cause I just need the value to insert

something like this if possible, please:

[wpv-imagen output="id"]

thanks again

#1268403

Please review our support policy: https://toolset.com/toolset-support-policy/
"When you need custom coding which extends Toolset functionality, we recommend contacting one of Toolset certified consultants."

You are one of these consultants.

So you are asking me to write the custom code that we advise clients to pay you to write. What have you tried so far? You can start by reading up on the Shortcode API to see how to create your own custom shortcodes: https://codex.wordpress.org/Shortcode_API

Show me some work, something we can debug together, and I'll offer advice.

#1268413

Dear Christian, I just asked wether a shortcode to write the ID of custom field (from toolset) exists, as toolset provides that solution for a similar field (featured image), Im not trying to take advantage of you or anybody, you replied with some code, Im not a coder myself thats why I use toolset, so I did not understand how to use your code, thats why I gave you an idea of what I was looking for, it was not a command or a coding quote:
I think you misunderstood my request and took a defensive and a bit agresive attitude, when its full of similar solutions in this forum and support,
I can show plenty of examples from other supporters, maybe you are not interested in doing this, and I understand if this is the case,
but a simple response such as

lucas toolset does not provide this, would have worked, implying that im trying to profit from your work is way out of line, i must say

#1268427

Unfortunately Toolset does not offer a shortcode to get a custom field image ID, I'm sorry if I wasn't clear about that. However, with some custom code, you could produce your own custom shortcode. Would you like to work on such a solution together? If so, I will be happy to help troubleshoot any of your code. As a certified Toolset consultant, I expect you to write the majority of the code and show some effort to work towards a solution. I have already provided a substantial amount of code for you, and now it's time for you to take over. I stand by my previous decision not to give you a cut-and-paste custom code solution, as per our support policy, even though there are other examples of that here in the forum.

#1285247

My issue is resolved now. Thank you!

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