Skip Navigation

[Resolved] Removing wrapping code from "no items found" loop

This support ticket is created 7 years, 6 months ago. There's a good chance that you are reading advice that it now obsolete.

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.

Sun Mon Tue Wed Thu Fri Sat
- 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 7:00 – 14:00 -
- 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 15:00 – 16:00 -

Supporter timezone: Europe/London (GMT+01:00)

This topic contains 1 reply, has 2 voices.

Last updated by Nigel 7 years, 6 months ago.

Assisted by: Nigel.

Author
Posts
#444879

Hi guys,

I've done what suggested here

https://toolset.com/forums/topic/view-is-inserting-formatting-and-code/

to remove wrapping code from some views.
Everything's fine except for one thing:

if the view returns no items the wrapping code is there again!

How can I get rid of it even in this case?

Since the code you suggested refers to <!-- wpv-loop-start --> and <!-- wpv-loop-end --> I've tried to add these comments event in the wpv-no-items-found section of my view layout but the system doesn't save this edit since it accepts only a single occurence of those comments.

How can I do this?
As @darrylschmidt suggested in the ticket above would you please add a feature request to add an option that enable users to activate/deactivate wrapping code per each view right inside the view setting GUI?

Thank you very much.
Best regards
Carlo

#445158

Nigel
Supporter

Languages: English (English ) Spanish (Español )

Timezone: Europe/London (GMT+01:00)

Hi Carlo

I made a minor modification to the code to handle the case where the loop results are empty (which would mean the wpv-loop-start comment would be missing from the string).

You can update the string returned for no results if needs be.

function prefix_clean_view_output( $out, $id ) {

    if ( $id == '375' ) { // edit for your view
        $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 { // no results returned by view
        	$out = '<strong>No items found</strong>';
        }
    }
    return $out;
}

The way our system works I can't turn this ticket into a feature request, I'm afraid, you will need to create a new thread and specify in the drop down that it is a feature request, and then it will get directly assigned to our developers. Sorry for the duplication that requires.

This ticket is now closed. If you're a WPML client and need related help, please open a new support ticket.