Skip Navigation

[Resolved] views result array as shortcode parameter

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

Problem:
Since View 1.11 default HTMl is wrapped around the View's Loop and this makes it impossible to populate things like charts or other 3rd Party Plugins with Views generated data.

Solution (include the steps to folow here):
At your own risk you can use this Custom Filter:

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

function prefix_clean_view_output( $out, $id ) {
    if ( $id == '375' ) {
        $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;
}

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.

This topic contains 36 replies, has 2 voices.

Last updated by Steve 5 years, 6 months ago.

Assigned support staff: Beda.

Author
Posts
#344998

I apologize, but it's not πŸ™‚

What do you mean with?

#345009

it was just about different mail addresses and so on…

thanks a lot for the video! looks quite easy. πŸ˜‰
for the moment i still need to concentrate on another project to get the presentation done, but i will give it another try later on.

best,
s

#345011

Sprichst Du Deutsch?

Ich "steige" nicht, was die 53 angeht. geht kein Lichtlein auf bei mir...

<==EDIT==>
Ja, hab's kapiert πŸ™‚
Deine "andere Email" πŸ˜›

Nun, in Englisch wieder...

Hope it will work on your end.
Please don't hesitate to get back here, in case you find troubles with the setup.

Thank you for your patience.

#345561

hej beda.

thanks again for the tutorial. i was able to reproduce it with one field/loop of mine and got a working line chart.

what i am still struggling with is the syntax of the ids array in my functions.php:

 if ( $id == '1' )

… works fine.

 if ( $id == '1,2,3,4,5' )

… doesn't work at all!

how does the syntax work with multiple ids?

best,
s

#345598

You need an array.

Excluding

$exclude_ids = array( 123, 456, 789 ); //SET YOUR EXCLUDING IDS HERE
    if ( ! in_array( $view_id, $exclude_ids ) {
...
}

Including

if (in_array($view_id, array(12, 13, 14) ) )  { //set your View ID's here
...
}

Please do not hesitate to open a new thread if other issues or problems arise

Thank you for your patience.

#345627

hej beda.

that's the pre-final post just for anybody else who might follow at any time, here' s the final code for the functions.php …

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
 
function prefix_clean_view_output( $out, $id ) {
	
	$exclude_ids = array( 12, 34, 56, 78  ); //SET YOUR EXCLUDING IDS HERE

    if ( !in_array( $view_id, $exclude_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 );
        }
    }
    return $out;
}   

thanks a lot beda for your help!!!

best,
s

#345628

one more time: thanks a lot beda for your help!!!

best,
s