Skip Navigation

[Closed] adding post_id parameter to types_render_field() function

The Toolset Community Forum is closed, for technical support questions, please head on to our Toolset Professional Support (for paid clients), with any pre-sale or admin question please contact us here.
This support ticket is created 11 years, 8 months ago. There's a good chance that you are reading advice that it now obsolete.
This is the community support forum for Types plugin, which is part of Toolset. Toolset is a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients and people who registered for Types community support can post in it.

This topic contains 7 replies, has 2 voices.

Last updated by mery 11 years, 8 months ago.

Assisted by: bruce.

Author
Posts
#17132

Hi there,

seems to me that this very useful function can only be used in the loop (as there is no way fo now to change the post it gets the custom fields for)

would be very useful to be able to pass a post_id in the arguments as right now I have to modify global $post before calling this function to achieve what I am after

Would the Types team comment in this ?

thanks

#17154

Hi Thomas,

It can't be done via the types_render_field function. You can use it in the types shortcode.

[types field='my-field' id='233']

To use it in your theme you can use something like:
<?php echo do_shortcode("[types field='my-field' id='233']"); ?>

Best regards,
Bruce

#17161

Hi ruce,

thanks for the reply

only I can't make it work and I don't see how this is implemented in the code

nothing indicates that an id param is used in case it exists (in frontend.php)

I'm using Types 0.1

is there a newer version ?

thanks

#17170

Hi Thomas,

The latest version is 1.0.4 - http://wordpress.org/extend/plugins/types/

Best regards,
Bruce

#17175

thanks Bruce,

this is in fact the version I am using

only in types_render_field()

global $post is used to get meta information

no way to pass an id there as far as I can see

any chance you might share where this is supposed to happen ?

thanks

#17180

Hi Thomas,

It only happens when called via the types shortcode. The line that does it is line 32:

// Switch the post if there is an attribute of 'id' in the shortcode.
$post_id_atts = new WPV_wpcf_switch_post_from_attr_id($atts);

Best regards,
Bruce

#17183

Ah thanks

only I am not using shortcodes

but rather accessing the types_render_field directly in my template

any chance the Type Team will consider adding a way to use $args['id'] in the types_render_field function to achieve the same result without having switch the global $post ?

It would be cleaner I think

#17184

Maybe I am missing something but could something along the line of :

if(isset($params['id']))
$post_id = $params['id'];
else
$post_id = $post->ID;

and using this variable instead of $post->Id in the get_post_meta calls

work

as it seems like $post is used mainly to get its ID

it seems to be working for me

let me know hat you think

thanks

The topic ‘[Closed] adding post_id parameter to types_render_field() function’ is closed to new replies.