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
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
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
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.
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
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.
My issue is resolved now. Thank you!