WordPress.org

Ready to get started?Download WordPress

Forums

Types - Custom Fields and Custom Post Types Management
[resolved] types_render_field / image with specific post ID (8 posts)

  1. matthias_123
    Member
    Posted 2 years ago #

    Hello !

    First of all: thanks for the plugin (I have been a fan of WPML - and now this plugin seems to be a worthy addition...)

    I need to load a specific image size (thumbnail) of an image I have uploaded with this plugin.
    Problem is, I have to request the image data outside the loop
    (usually WP offers the possibility to load meta values by requesting the data like:
    get_post_meta($post_id, 'wpcf-thumbnail', true);

    But since the only meta value stored is the absolute URL to the image I can´t render the image in the size I want:

    types_render_field("thumbnail", array('size' => 'thumbnail'));
    I would (quite desperately) need a possibility the use the types_render_field function with a specific post ID (OR: a possiblity to extract the ID of the image so I could render the correct size myself - but I´d rather prefer a possibility which includes the use of the types_render_field function)

    does anyone have an idea ?

    thanks,
    matthias

    http://wordpress.org/extend/plugins/types/

  2. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    This is a very good suggestion. I'm adding it to our todo list.

    BTW, as you're using and testing Types, don't forget to go back to the project page and mark that it's working for you:
    http://wordpress.org/extend/plugins/types/

  3. matthias_123
    Member
    Posted 2 years ago #

    Thanks for your quick reply !

    I will of course mark this plugin as working,
    however:
    Can you thing of any quick workaround to my problem ?
    (getting either the image id or - better - a code similiar to types_render_field ?

    As you must kind of load the image data somewhere, could you possibly point me towards where the functions code actually performs it´s calculations ?

    I would kind of have to complete the project I am working on ´till tomorrow - and it would be pretty cool if I could continue with the plugins I have already integreted...

    Thanks,
    matthias

  4. peterarends
    Member
    Posted 2 years ago #

    Too bad they still haven't implemented this basic functionality.

    A quick workaround is using this to get the ID (they us it too in file.php):

    global $wpdb;
    	$attachment_id = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_type = 'attachment' AND guid=%s",$url));
  5. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    We do our best to introduce new features, but you'd be surprised to know that just asking for something doesn't make it instantly appear in the code.

    Post ID is now part of Types 0.9.5. This version is not released yet and is currently in internal QA. It should be ready in about a week.

  6. l.stavrev@web-minister.com
    Member
    Posted 2 years ago #

    Hi, I use the following code to temporary set the post ID, then restore the original $post value (you need to set "$YOUR_ID"):

    global $post;

    ### (1/2) Workaround to missing feature to select images by ID ($post->ID).
    $post_orig = $post;
    // Now set the post data and execute the needed function, then restore the post value:
    $post->ID = $YOUR_ID;
    ### (END 1/2) Workaround to missing feature to select images by ID ($post->ID).
    
    $post_images_list = types_render_field( "post_images_list", $parameters );
    
    ### (2/2) Workaround to missing feature to select images by ID ($post->ID).
    // Restore the original data
    $post = $post_orig;
    ### (END 2/2) Workaround to missing feature to select images by ID ($post->ID).

    Hope it helps somebody...

  7. AmirHelzer
    Member
    Plugin Author

    Posted 2 years ago #

    Sure helps. Thanks.

  8. l.stavrev@web-minister.com
    Member
    Posted 2 years ago #

    Sorry, it seems my above code is not working (it seems the $post object couldn't be copied to another variable as an array..., so now in the following code I change the $post->ID only).

    Here is the corrected code (it seems to work fine now, sorry again!):

    global $post, $post_id_orig;
    
    ### 2012-06-04 - (1/2) Workaround to missing feature to select images by ID ($post->ID).
    $post_id_orig = $post->ID;
    // Now set the post data and execute the needed function, then restore the post value:
    $post->ID = $YOUR_ID;
    ### (END 1/2) 2012-06-04 - Workaround to missing feature to select images by ID ($post->ID).
    
    $post_images_list = types_render_field( "post_images_list", $parameters );
    
    ### 2012-06-04 - (2/2) Workaround to missing feature to select images by ID ($post->ID).
    $post->ID = $post_id_orig;
    ### (END 2/2) 2012-06-04 - Workaround to missing feature to select images by ID ($post->ID).

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags