Skip Navigation

[Resolved] How to use views PHP API function get_view_query_results with third party plugin

This thread is resolved. Here is a description of the problem and solution.

How to use views PHP API function get_view_query_results with third party custom plugin

you should try to use the WordPress standard hook wp_loaded that will allow you to use the view's PHP API function with custom plugin in this case.

You can find the proposed solution, in this case with the following reply:

Relevant Documentation:

This support ticket is created 5 years 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.

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 12 replies, has 2 voices.

Last updated by Franck 5 years ago.

Assisted by: Minesh.



I have a big problem with a view.

On my view hidden link
I try to query the "Affichages prévisions" by taxonomie signe and type horoscope. And i have to use it with api.
The problem is the filters doesn't work.
You can see the result of the print_r here : hidden link

here is my code :
$args = array(
'wpvtypehoroscope' => "week-end",
'signe' => "bélier",
$vue_affichage = get_view_query_results(30829, $args);


Maybe i have made an mistake. But i have tried lot of thing.....



Languages: English (English )

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

Hello. Thank you for contacting the Toolset support.

Well - I need to review on your site how you configured your view and on which PHP template you added the code you shared.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually need to request temporary access (WP-Admin and FTP) to your site. Preferably to a test site where the problem has been replicated if possible in order to be of better help and check if some configurations might need to be changed.

I have set the next reply to private which means only you and I have access to it.



Languages: English (English )

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

Can you please check now.

I see you have passed the argument as given under:

$args = array(
'wpvtypehoroscope' => "week-end",
'signe' => "bélier",

Where for the argument signe you need to pass the slug belier instead of bélier.

Do you see its working now?

Capture d’écran 2019-04-08 à 13.15.30.png
Capture d’écran 2019-04-08 à 13.09.55.png

No it is not working.

And, we can even see it is not working if wee add argument id publication.

I have make lot of tests. ...
Even if i make the view as my first picture it is not working.
Nevertheless if i manage the id publication like my second picture it is working. But the same argument passed in api doesn't work.



Languages: English (English )

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

Well - I see number of results now with the following page:
=> hidden link

Can you please share your expected output.


The number is expected : 27466

But as we can see, there is first problem, the view show posts with taxonomie signe are not belier.

Ex : hidden link

Thera others problems, i ask post before today, and the view give posts after.

What is strange is hidden link
On this page i call the similar view but without api, and it is working.
It is this view : hidden link



Languages: English (English )

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

Well - I tested with clean install and I've setup a custom post type with two taxonomies.

Then I've created the following shortcode and added it to current theme's functions.php file on my test install:

function func_call_view_api() {
	$args = array(
              'wpvemployeedepartment' => "dept-account",
              'wpvstudenttype' => "week-end",

$results = get_view_query_results(222,null,null,$args);
echo "<pre>";
print_r($results );

add_shortcode( 'get_api_view_res', 'func_call_view_api' );

And created a new page and added the above shortcode and I see that it works just fine.

Can you please check with minimum install on another install.


I am bit surprised with your answer. Of course if we change all, it could be work, i have also told you that the view work on the page when i used it without api.

My plugin is clean and easy. I call a view and the view give a bad answer 🙁

What is minimum install ? as you can see i almost use Toolset without other plugin....
But beacause i have to fix this problem, and even i have big trafic right now, i have turn off all plugins and turn on TwentyNineteen Theme and the problem stay the same.

I think i i put my fonction in a shortcode it would work , but i can use shortcode because i need a empty page juste with json code.

So, what i have to do ?

thanks a lot.


Maybe the problem is we have to make some includes before code to use the api.
So with with shortcode it works because all includes are done.


Sorry, i forgotten the video : hidden link



As i expected, with a shortcode it works perfectly.
hidden link

My problem is i need an empty page with just json result, i understand for to that i can not use shortcode, i have to use plugin and call the view by the same way i have shown you.

I really think to use the api view toolset with parameters we have to make some WP includes before, but which one.... that is the question.

Thanks a lot for your help.



Languages: English (English )

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

Well - I think I found the solution for you.

I've created the following view - which is having same settings as per your other view which you are using originally:
=> hidden link

I've changed the hook to wp_loaded instead of init with your plugin file etoiles.php:

add_action('wp_loaded', 'se67905_my_template');

And I've used the following code within the if condition:

$args = array(
	'wpvtypehoroscope' => "week-end",
              'wpvsigneastrologique' => "belier",
		$res = get_view_query_results(30880,null,null,$args);
				echo "<pre>";

I can see its displaying the expected results:
=> hidden link

Can you please confirm?


My issue is resolved now. Thank you!

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.