Skip Navigation

[Resolved] accessing view results programmatically

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.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 3 replies, has 2 voices.

Last updated by Minesh 1 year, 11 months ago.

Assisted by: Minesh.

Author
Posts
#2520959

Hi there

We have a view whose results are a specific set of users with some custom field data.

We'd like to be able to email these users - basically a mail merge that includes their custom details.

Is there a way to access the view programmatically so that we can do that?

Thank you

#2522347

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

When you say programmatically - you mean you want to access the view using php - correct? If yes:
- You can use the view's PHP API function: render_view()

For example:

echo render_view(999 );

Where:
- replace 999 with your original view ID

More info:
- https://toolset.com/documentation/programmer-reference/views-api/#render_view

#2524419

Hi

Thank you for the response. We're trying to access the data returned in the view.

Basically here's what we're trying to accomplish: this is for an education site where we need to email users belonging to specific roles whose scores are too low.

Currently we have a view that returns the correct set of users and displays their name, email address, and their course score.

Rather than, or in addition to , looping over the users and displaying them on screen, we'd like to be able to be able to email the users.

If we could access the view through a php function for example, we'd able to use returned users to generate emails.

Thank you

Simon

#2524631

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

In that case you should use the view's PHP API function: get_view_query_results()
=> https://toolset.com/documentation/programmer-reference/views-api/#get_view_query_results

For example:

$users_data = get_view_query_results( 9999);
foreach ( $users_data as $user_data) {
    echo $user_data->data->user_email;
}

Where:
- Replace 9999 with your original user view ID.

You can adjust the above code as required.