Hello!
I use the Views to create JSON. I need a clean outpoot. I use a filter, and it helps for [wpv-items-found]:
add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
function prefix_clean_view_output( $out, $id ) {
if ( $id == '4' ) { //Please adjust to your Views ID
$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 );
}
}
return $out;
}
However, if there are no posts in the loop, the output is dirty. Div is displayed for [wpv-no-items-found].
How can I remove it?
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Hello. Thank you for contacting the Toolset support.
Could you please share your view's loop output section code here.
<div id="wpv-view-layout-196-CATTRe4d1e819971a8602be869fdccecc8998TCPID6" class="js-wpv-view-layout js-wpv-layout-responsive js-wpv-view-layout-196-CATTRe4d1e819971a8602be869fdccecc8998TCPID6" data-viewnumber="196-CATTRe4d1e819971a8602be869fdccecc8998TCPID6" data-pagination="{"id":"196","base_permalink":"/ulmart/bot/?wpv_view_count=196-CATTRe4d1e819971a8602be869fdccecc8998TCPID6&wpv_paged=WPV_PAGE_NUM","query":"normal","type":"disabled","effect":"fade","duration":500,"speed":5,"pause_on_hover":"disabled","stop_rollover":"false","cache_pages":"enabled","preload_images":"enabled","preload_pages":"enabled","preload_reach":1,"spinner":"builtin","spinner_image":"<em><u>hidden link</u></em>","callback_next":"","manage_history":"enabled","has_controls_in_form":"disabled","infinite_tolerance":"0","max_pages":0,"page":1,"loop":{"type":"","name":"","data":[],"id":0}}" data-permalink="/ulmart/bot/?wpv_view_count=196-CATTRe4d1e819971a8602be869fdccecc8998TCPID6">
[]
</div>
I just need to [].
My JSON is not valid because of div.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I think you didn't get my point.
Edit your view -> go to loop output section and share the code you have added to it here:
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Could you please try to use following code in your view's loop output:
[wpv-layout-start]
[wpv-items-found]
<!-- wpv-loop-start -->
[
<wpv-loop>
[wpv-item index=1]
{"id": "[wpv-post-id]",
"title": "[wpv-post-title]"}
[wpv-item index=other]
, {"id": "[wpv-post-id]",
"title": "[wpv-post-title]"}
</wpv-loop>
]
<!-- wpv-loop-end -->
[/wpv-items-found]
[wpv-layout-end]
[wpv-conditional if="( '[wpv-found-count]' eq '0' )"]
[]
[/wpv-conditional]
Add following code to your view's loop output JS box:
jQuery(document).ready(function($){
$('.js-wpv-view-layout').remove();
});
I hope above solution will help you to resolve your issue.
Sorry, this does not work. div is created in any case, even when [wpv-no-items-found] is missing.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
Can I have access details and problem URL where you are using this view's JSON output
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
*** 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 would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site. This is also a reason the backup is really important. If you agree to this, please use the form fields I have enabled below to provide temporary access details (wp-admin and FTP).
I have set the next reply to private which means only you and I have access to it.
Minesh
Supporter
Languages:
English (English )
Timezone:
Asia/Kolkata (GMT+05:30)
I've changed your loop output code as given under:
[hide-it][wpv-layout-start][/hide-it][wpv-items-found]<!-- wpv-loop-start -->[<wpv-loop>[wpv-item index=1]{"id": "[wpv-post-id]", "title": "[wpv-post-title]"}[wpv-item index=other], {"id": "[wpv-post-id]", "title": "[wpv-post-title]"}</wpv-loop>]<!-- wpv-loop-end -->[/wpv-items-found][hide-it][wpv-layout-end][/hide-it][wpv-conditional if="( '[wpv-found-count]' eq '0' )"][][/wpv-conditional]
And added following shortcode to your theme's functions.php file:
add_shortcode('hide-it', 'hide_it_func');
function hide_it_func(){
return;
}
Now I can see that there is no Div added.
This is a great solution. Thank you, I'm happy.