Skip Navigation

[Resolved] Views API, Raw Output

This support ticket is created 8 years, 3 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
- 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 8:00 – 17:00 -
- - - - - - -

Supporter timezone: America/Sao_Paulo (GMT-03:00)

This topic contains 15 replies, has 3 voices.

Last updated by Adriano 8 years ago.

Assisted by: Adriano.

Author
Posts
#354147

I am trying to: Ouput a nested taxonomy view via a custom shortcode.

I visited this URL:
https://toolset.com/documentation/user-guides/views-api/
https://toolset.com/forums/topic/why-is-my-views-wrapped-in-new-div/

I expected to see: raw values

Instead, I got: values wrapped in a pagination div.

My code:

function my_custom_shortcode( $atts, $content = null ) {
	$args = array(
		'title' => 'My View',
		'raw' => 'true',
	);
	return trim(render_view($args));
}

add_shortcode( ' my_custom', 'my_custom_shortcode' );

Essentially, how do I output the view in a raw format (without wrapping it in html)? Even with adding the code in the second link mentioned above, I still get an HTML output.

Thanks in advance!

#354288

shekhar
Supporter

Hi there,

Thank you for contacting Toolset support.

#1
The ticket you have mentioned is in reference to using the views using [wpv-view], if you render the views using [wpv-view] it still works.

#2
You are using custom shortcode to display the view so you need to modify the code and use the following in your shortcode function:

function my_custom_shortcode( $atts, $content = null ) {
    $args = array(
        'title' => 'My View',
        'raw' => 'true',
    );
$out = render_view($args);
return without_html($out);
}
 
add_shortcode( 'my_custom', 'my_custom_shortcode' );

add add a custom function which makes the output raw
//making output raw made by render_view function
function without_html($out) {
	$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

#354328

Hi Shekhar,

Thanks for your response! We've implemented the code that you've mentioned, however, we're still getting HTML outputted.

Perhaps it might be useful to explain what we want to accomplish:

1) Use a nested View with Taxonomies, to get 'Child Taxonomy' Values. We have a hierarchical taxonomy (let's call it 'MyTaxo'), such as:

- Parent 1
    - Child 1
    - Child 2
- Parent 2
    - Child 3
    - Child 4

Our 'parent' taxonomy view, 'Taxonomy Child Wrapper':

Filters =
Taxonomy parent filter: Select taxonomy terms whose parent is None.

Taxonomy term filter: Taxonomy is set by the current page


[wpv-layout-start]
	[wpv-items-found]<wpv-loop>[wpv-view name="Taxonomy Child"]</wpv-loop>[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

Our 'child' taxonomy view, 'Taxonomy Child':

Filters =
Taxonomy parent filter: Select taxonomy terms whose parent is the value set by the parent view.
Taxonomy term filter: Taxonomy is set by the current page

[wpv-layout-start][wpv-items-found]<wpv-loop>[wpv-taxonomy-title]</wpv-loop>[/wpv-items-found]
	[wpv-no-items-found]
		<strong>[wpml-string context="wpv-views"]No items found[/wpml-string]</strong>
	[/wpv-no-items-found]
[wpv-layout-end]

2) Use the ouput of that nested view as a parameter using 'Third-party shortcode arguments:'

[wpv-view name="My Listing View" wpvparenttaxo="[child_taxo_mytaxo]"]

Our shortcode:

/* Toolset: Remove HTML wrapper:
================================================== */
function without_html($out) {
    $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;
}

/* Toolset: Taxonomies > Child Wrapper
================================================== */
function child_tax_mytaxo_shortcode( $atts, $content = null ) {
	$args = array(
		'title' => 'Taxonomy Child Wrapper',
        'raw' => 'true',
	);
	$out = render_view($args);
	return without_html($out);
}

add_shortcode( 'child_taxo_mytaxo', 'child_tax_mytaxo_shortcode' );

Note: the above views and shortcode are 'working' in the sense that they output the correct information. The problem is that they are still being wrapped by the Views div.

Thanks again in advance!

#354496

shekhar
Supporter

Hi there,

Thank you for getting back to us.

#1

As your code of outputting the views is this

[wpv-view name="My Listing View" wpvparenttaxo="[child_taxo_mytaxo]"]

Could you please mention if you have used filter to remove html for the “My Listing View”?

#2
Could you please check if the using just the custom shortcode on any page “[child_taxo_mytaxo]” outputs html or not?

#3
If you have done both #1 and #2 both but the results is still showing html, I 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. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

I would also recommend to backup your database and website first before we proceed. You can use a plugin for this if you like. I often use the Duplicator plugin for this purpose.
See: http://wordpress.org/plugins/duplicator/

Thanks

#354910

Hi Shekhar,

Thanks for your response:

RE: [child_taxo_mytaxo]

Yes, I can confirm that this outputs HTML

RE: Filter to remove HTML

If you are referring to the code below, then yes, we do have it implemented:

function without_html($out) {
    $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;
}

We're happy to provide access, so please send me the form that you need to acquire this access.

Thanks in advance!

Best,

Ryan

#354912

shekhar
Supporter

Hi there,

I 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. You will find the needed fields for this below the comment area when you log in to leave your next reply. The information you will enter is private which means only you and I can see and have access to it.

I would also recommend to backup your database and website first before we proceed. You can use a plugin for this if you like. I often use the Duplicator plugin for this purpose.
See: http://wordpress.org/plugins/duplicator/

Thanks

#355091

shekhar
Supporter

Hi there,

#1
Shortcode [child_taxo_mytaxo] in not working, are you sure you have inserted the function for this?

#2
I can not replicate the steps you mentioned in your 2nd reply, have you changed the views name??

i will wait for your feedback.

Thanks

#355207

Hi Shekar,

Thanks for your response. The shortcode is, indeed, different. Sorry for any misunderstanding. We often anonymize / simplify things before posting in here. Also, is there a way for me to change my replies to private?

You will find the shortcodes and views that we are using here: /themes/~/app/toolset.php

Best,

Ryan

#355387

shekhar
Supporter

Hi there,

Thank you for getting back to us.

As you described in your previous reply, that you want the views as such:

- Parent 1
    - Child 1
    - Child 2
- Parent 2
    - Child 3
    - Child 4

#1
For this you have created 3 views which is not showing any results. The best way to do this as follows:

a) Create a taxonomy view which filters that parent is none, as you have done on "Neighborhood Taxonomy Parent", The "Taxonomy is set by the current page" is not necessary.

b) Inside the Loop output of "Neighborhood Taxonomy Parent" you need to add the child view "Neighborhood Taxonomy Child".

c) In the "Neighborhood Taxonomy Child" make sure you used the filter as below only:
- Select taxonomy terms whose parent is the value set by the parent view.
- Make sure to check "Don't show empty terms" on query options of the view if you don't want to show the no result found text.

Once you have done this the view will look like as you need.

Can you try this once and have a look?

#2
Displaying Raw Output

1) Once you have created the view correctly, you can use the function provided in the above reply to display the raw output, currently the view is not properly setup as it shows "no result found" only.

I will wait for your feedback.

Thanks

#355444

Hi Shekhar,

Thanks for your response. Sorry for not clarifying, we actually are using taxonomies on pages (we're using pages instead of default taxonomy archives because we want control over the template).

As such, I've updated the taxonomy for the test page you created /~/test-page-created-by-support/

So, now on this page, the shortcode is outputting the correct value, it's just wrapped (still) in the views div.

Please let me know if you need anything else to help diagnose and proceed.

Thanks in advance!

Ryan

#355445

shekhar
Supporter

Hi there,

I think the problem is already solved, as [parent_taxo_neighborhood] and [proptrans_status] is not wrapped into html anymore.

I will wait for your feedback.

Thanks

#355448

Hi Shekhar,

Thanks for the fast response. It does look like those shortcodes are, indeed no longer wrapped in HTML. However, our shortcode [child_taxo_neighborhood] still is wrapped in HTML, could you please let us know how we could get this shortcode to also not be wrapped in HTML.

As well, if you could, we would massively appreciate if you could briefly outline what changes / steps you took.

Thanks in advance!

Best,

Ryan

#355525

shekhar
Supporter

Hi there,

#1
The [child_taxo_neighborhood] has another view on it's loop, could you use another short code for the view inside the loop.
Does this solve the problem?

#2
if you have enabled any cache plugin, please make sure to turn it off while checking the site.

I will wait for your feedback.

Thanks

#355602

Hi Shekhar,

- Thanks for your response. Regarding a few of the last threads

RE: ' [child_taxo_neighborhood]' has another loop.

- Yes, we are aware of this. We don't need a solution for removing an HTML wrapper for only one specific instance, rather a solution for removing HTML wrappers that can be applied in various instances.

RE: Cache

- We are not running any caching tools

RE: Our thread from December 23, 2015 at 11:17 am

- Could briefly outline what changes / steps you took.

I guess I'm having a hard time understand why there isn't some easy override to prevent a view from being wrapped in the toolset html. I understand why sometimes it is necessary to wrap a view in HTML, but I feel that there should also be a way to have the view be just a value (whether it be in a shortcode or not). Can this please be added to a feature request?

Thanks in advance

#355748

shekhar
Supporter

Hi there,

Currently, you need to create a function for each short code instances.

e have already submitted an feature request regarding this feature. but we haven't still any exact date for the fix. We will let you know once the feature will be added to views.

Thanks

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