I have a CPT "Legislators" and a view that filters them. It accepts URL_PARAMs (attached image). It works just fine when I embed the view on a page, and filters the results as expected.
I have a script that outputs JSON data from this view, using get_view_query_results(), however I cannot get that function to accept my search parameters.
The expected result is to return only Legislators where state=Virginia. The actual result is it's returning all of the data without filtering by state, as you can see here: hidden link
[code]
<?php
/*
Template Name: Alex
*/
header('Content-Type: application/json');
include("../../../wp-load.php");
// Get the results of the Toolset Legislators-JSON view and output it as json.
$args = array(
'state' => "Virginia",
'wpcf-state' => 'Virginia'
);
foreach ( $filtered_posts as $filtered_post ) {
$key = $filtered_post->ID;
$meta = get_post_meta($key);
/** Do stuff with the data here **/
}
echo json_encode($returnArray);
?>
[/code]
Is there any documentation that you are following?
Thank you for contacting us and I'd be happy to assist.
If the view's query filter is set to filter by the URL parameter(s) and the URL of the page doesn't have those values, you can set them in the code through the super global '$_GET'.
( ref: hidden link )
For example:
....
// set 'district' URL parameter value
$_GET['district'] = 'abc';
// set 'state' URL parameter value
$_GET['state'] = 'def';
// set 'branch' URL parameter value
$_GET['branch'] = 'ghi';
$filtered_posts = get_view_query_results( 9627,null,null,$args);
....