It looks like the "visibility" block includes an array with a "1" representing each row, if I'm reading their data structure correctly. In order to build this, I need to loop over the data twice - once for the custom fields of each post, and again separately to add a row in the visibility section. This is not possible in a single View. Only one loop is possible in each View, and we would use the first loop to build out each item in the data block like this:
[
"3 Amigos",
"Mexican on kildaire farm rd in cary",
"Business",
"Wake",
"149,000",
"3,200",
"21.00",
""
]
We can try to create the full structure with two Views instead, and combine their results to produce the entire output. If any filters are in place on the first View, they must be identical in the second View. They must respond to the same URL parameters if you allow your Users to filter using a parametric search. So those are the two potential roadblocks I can predict, but there may be others I cannot anticipate.
First, you need output formatted to work in the "data" block of the JSON object you provided. This will be View 1. Create a View of posts with the following Loop Output code structure:
[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>,"[wpv-post-featured-image size="custom" width="160" height="120" crop="true"]","[wpv-conditional if="( $(wpcf-listing-name) ne '' )"][types field='listing-name'][/types][/wpv-conditional]","[wpv-conditional if="( $(wpcf-property-type) ne '' )"][types field='property-type'][/types][/wpv-conditional]","[wpv-conditional if="( $(wpcf-city) ne '' )"][types field='city'][/types][/wpv-conditional]","[wpv-conditional if="( $(wpcf-price) ne '' )"]$ [types field='price'][/types][/wpv-conditional]","[wpv-conditional if="( $(wpcf-size) ne '' )"][types field='size'][/types][/wpv-conditional]","[wpv-conditional if="( $(wpcf-rate) ne '' )"]$ [types field='rate'][/types][/wpv-conditional]","[wpv-conditional if="( $(wpcf-rent) ne '' )"]$ [types field='rent'][/types][/wpv-conditional]"]</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found][/wpv-no-items-found][wpv-layout-end]
It may be required to add the output="raw" attribute to some of these Types field shortcodes to prevent formatting from breaking your data structure.
Then, you must create View 2, which outputs a "1" for each row of results. It should use the same filters as View 1, but have a different Loop Output:
[wpv-layout-start][wpv-items-found]<!-- wpv-loop-start --><wpv-loop>[wpv-item index=1]1[wpv-item index=other],1</wpv-loop><!-- wpv-loop-end -->[/wpv-items-found][wpv-no-items-found][/wpv-no-items-found][wpv-layout-end]
In your child theme's functions.php file, you must insert the following code to remove all extra formatting and markup from the output of these Views:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
$ids = array( 12345,67890 );
if ( in_array( $id, $ids )) {
$start = strpos( $out, '<!-- wpv-loop-start -->' );
if (
$start !== false
&& strrpos( $out, '<!-- wpv-loop-end -->', $start ) !== false
) {
$start = $start + strlen( '<!-- wpv-loop-start -->' );
$out = substr( $out , $start );
$end = strrpos( $out, '<!-- wpv-loop-end -->' );
$out = substr( $out, 0, $end );
} else {
$start = strpos( $out, '>' );
if ( $start !== false) {
$out = substr( $out, $start + 1 );
$end = strpos( $out, '<' );
$out = trim(substr( $out, 0, $end ));
}
}
}
return $out;
Replace 12345,67890 with a comma-separated list of both View IDs. Insert both Views on the same page so we can verify the output, then we can try to combine their results to produce the full JSON data structure. Let me know if you get stuck and I can take a quick look.