Skip Navigation

[Closed] help with displaying a view in php

This support ticket is created 3 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Our next available supporter will start replying to tickets in about 0.91 hours from now. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Karachi (GMT+05:00)

This topic contains 9 replies, has 3 voices.

Last updated by Waqar 3 years, 5 months ago.

Assisted by: Waqar.

Author
Posts
#1816963

Tell us what you are trying to do?
i need to display a user custom field based on a specific user id of "546" .. tried to do this with a view within a view within a view but i guess thats not possible so i need to do it with php.

Is there any documentation that you are following?
https://toolset.com/documentation/programmer-reference/views-api/ ( i dont understad this one)
https://toolset.com/forums/topic/using-view-shortcode-as-php/

Is there a similar example that we can see?

What is the link to your site?

so i need to display a view that will show me a single user based on the user ID of 546, and the only thing I need the view to output would be a custom with the slug "financial-institution".

I got this to work.... with a posts view, but when i tried to use it to display users it would not work.
echo render_view( array( 'name' => '_test' ) );
Ofcourse the above does not have any arguments or conditions, i was just testing and seemed like a good place to start.

this seams to be, or should be pretty easy. what am i missing.

#1816973

ok i actually got it to work with this code:

$clientuserid = bp_displayed_user_id();
echo "<br>";
echo $clientuserid;
echo "<br>";
echo types_render_usermeta( "financial-institution", array( "user_id" => $clientuserid ) );

the above code gets the userid of the user profile someone is on, stores it in a variable and then i use that variable to render the data in the usermeta ...

my question is, on this: types_render_usermeta( "financial-institution", array( "user_id" => $clientuserid ) );
how do i get it to output the raw data, this is dropdown data so i need to display the raw data not the field name or whatnot.

#1817853

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

The function types_render_usermeta will normally output the formatted version of a field.

If you want the raw value as stored in the database you could try adding the argument output="raw", e.g.

types_render_usermeta( "financial-institution", array( "user_id" => $clientuserid, "output" => "raw" ) );

or you could simply access the raw data directly using get_user_meta (https://developer.wordpress.org/reference/functions/get_user_meta/)

#1821261

great. so i think the last thing is how do i display a view in php:

echo render_view( array( 'name' => '_test' ) );

with the id of the post set to "1933" ?

#1821803

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for writing back.

If your goal is to pass the post ID "1933" as an attribute value to view in PHP, you can use:
( ref: https://toolset.com/documentation/programmer-reference/views-api/#render_view )


$args = array(
    'name' => '_test',
    'myattribute' => '1933'
);
echo render_view( $args );

Note: you'll replace "myattribute" with the attribute used in the view.

#1822651

so whats the post id attribute ? "post_id" ?

'post_id' => '1933' ?

i dont see anywhere in the documentation that explain or shows the post id attribute

#1822821

i figured it out .. duh. but I am getting an error .. i am using this code:

$args = array(
'name' => '_test',
'fiid' => $profilefiifraw
);
echo render_view( $args );

but wordpress tells me:

"There has been a critical error on your website."

when i do ...

obviously $profilefiifraw is a variable i have the post id set to .

#1825815

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

Thanks for the update.

The code snippet that you shared, itself seems correct. But it would be difficult to troubleshoot without knowing the context where it is being placed.

Can you please turn on WordPress debugging and share any errors or warnings shown on the screen or in the server's error logs?
( ref: https://wordpress.org/support/article/debugging-in-wordpress/ )

Please also share some information about how and in which file you plan to use this snippet?

#1829993

ok i will do that and get back with you. thank you.

#1832773

Waqar
Supporter

Languages: English (English )

Timezone: Asia/Karachi (GMT+05:00)

{ticket status updated}

The topic ‘[Closed] help with displaying a view in php’ is closed to new replies.