Skip Navigation

[Resolved] New Line after every Views shortcode insert

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

Problem:
How to display clean raw output using view

Solution:
You can use view's filter "wpv_filter_wpv_view_shortcode_output" to display clean raw output using views.

You can find proposed solution, in this case, with the following reply:
https://toolset.com/forums/topic/new-line-after-every-views-shortcode-insert/#post-838454

Relevant Documentation:

This support ticket is created 6 years, 7 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.

No supporters are available to work today on Toolset forum. Feel free to create tickets and we will handle it as soon as we are online. Thank you for your understanding.

Sun Mon Tue Wed Thu Fri Sat
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 -
- 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 14:00 – 18:00 -

Supporter timezone: Asia/Kolkata (GMT+05:30)

Tagged: 

This topic contains 6 replies, has 2 voices.

Last updated by saint 6 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#833081

Hi guys,

I'm adding in new Views that pull back specific fields from both many-to-many related CPTs, as well as also from CTs.

One issue that I keep getting is, every time I add in a View, it creates a new line. hidden link

How do I get rid of the new line?

Thanks,

#838454

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

Well - when you add view, it will add view's wrapper divs. If you are just using view to just display the content and want to just output view's results as raw output.

Please add following code to your current theme's functions.php file and replace the view' ids.

add_filter( 'wpv_filter_wpv_view_shortcode_output', 'prefix_clean_view_output', 5, 2 );
 function prefix_clean_view_output( $out, $id ) {

$view_ids = array(9999,888,777);   // replace your original view dis with this array

if (in_array($id, $view_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;
}
#838848

Hi Minesh,

Thanks so much for the code! Is there any way to do this more... normally? Maybe with something like output='raw'? Example:

[types termmeta="gender" output='raw'][/types]

I have a _lot_ of fields and term metas to setup and this 'code hack' seems extremely cumbersome to implement as a solution and not really scalable/friendly... Do you know if there's a normal, "non-hacky" way to do this?

I can't imagine just pulling back custom fields and term metas only without any formatting would be an edge case and would probably be used often...

Thank you,

#839457

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Well - I'm talking about view's shortcode here. You are using view's shrotcode and to have raw output using view's I have only solution to offer you which I shared in my previous reply.

Yes - obviously there is raw output available with Types shortcode but NOT with views. We have feature request already registered for it.

#839784

"We have feature request already registered for it."

To make sure I understand you, you mean, feature request to raw output for Views? If so, do you know when this will be released?

This is a critical piece of functionality since having to update $view_ids every time I add a new view to pull back specific custom fields might be okay with 5-10 fields, but unsustainable from a maintainability perspective as I add 20, 30, 40 fields or term metas.

The process to show a related Term Meta via a View is already incredibly involved (Another plugin does this in 4 clicks, Views takes over 10+ clicks across multiple tabs to query and display just 1 related field.)

Please, please put in a feature request to improve the Usability and UX of Toolset so we can accomplish more with fewer steps.

Thank you,

#839848

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

To make sure I understand you, you mean, feature request to raw output for Views? If so, do you know when this will be released?
==> Yes, the feature request is filed against view's plugin to have raw output. We already filed the feature request but there is no ETA on it as it's totally depends upon Developer's predefined priority and available resource. This is something judge by developers not supporters.

#843812

Thanks, Minesh. Appreciate your note. Please see if you can ask them to expedite. This is a much-needed request.