Home Forums Types Community Support [Closed] adding post_id parameter to types_render_field() function

[Closed] adding post_id parameter to types_render_field() function

This topic contains 7 replies, has 2 voices, and was last updated by  mery 2 years, 2 months ago. The support staff assigned to this topic is bruce.

Viewing 8 posts - 1 through 8 (of 8 total)
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

bruce
Forum moderator

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

bruce
Forum moderator

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

bruce
Forum moderator

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

Viewing 8 posts - 1 through 8 (of 8 total)

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

Support Policy

ToolSet staff will help you use Types, Views and CRED correctly, provide any information you need, help troubleshoot problems and advice on best-practices.

Please make sure to issue only one topic per each support ticket.

Need custom programming work for your site? Check out our certified partners.