Output a Raw Views Loop

You have no access to this specific snippet

Let us know if this snippet is not working for you:

This snippet doesn’t work
0 0 votes
Article Rating
Subscribe
Notify of
guest

3 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Christian Cox
7 years ago

I propose the following update to account for the “no items found” condition. This is important if you’re outputting different raw text depending on whether or not results are found. For example, say you want to use a View to output a CSS class for some element. If results are found, you want to add class “a” but if no results are found you want to add class “b”.

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );

function prefix_clean_view_output( $out, $id ) {
    if ( $id == '71' ) { //Please adjust to your Views ID
        $start = strpos( $out, '' );
        if (
            $start !== false
            && strrpos( $out, '', $start ) !== false
        ) {
            $start = $start + strlen( '' );
            $out = substr( $out , $start );
            $end = strrpos( $out, '' );
            $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;
}