[Closed] adding post_id parameter to types_render_field() function

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

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

Viewing 8 posts - 1 through 8 (of 8 total)
Author Posts
Author Posts
August 19, 2012 at 1:30 pm #17132

mery

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

August 20, 2012 at 5:14 am #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

August 20, 2012 at 7:44 am #17161

mery

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

August 20, 2012 at 1:36 pm #17170

bruce
Forum moderator

Hi Thomas,

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

Best regards,
Bruce

August 20, 2012 at 1:40 pm #17175

mery

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

August 20, 2012 at 1:48 pm #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

August 20, 2012 at 1:54 pm #17183

mery

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

August 20, 2012 at 2:01 pm #17184

mery

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.