Skip Navigation

[Résolu] views result array as shortcode parameter

Ce fil est résolu. Voici une description du problème et la solution proposée.

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 support ticket is created Il y a 8 années et 5 mois. 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
- - 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00 14:00 – 20:00
- - - - - - -

Supporter timezone: Asia/Ho_Chi_Minh (GMT+07:00)

This topic contains 36 réponses, has 2 voix.

Last updated by Steve Il y a 8 années et 5 mois.

Assisted by: Beda.

Auteur
Publications
#342756

hej toolset.

i am trying to bring the values from a group of repeating fields to a line chart via nested shortcode.
i use wp-charts the final terms should lokk something like this …

[wp_charts title="linechart" type="line" align="" margin="5px 20px" datasets="[wpv-view name='Werte, Gewicht'] next [wpv-view name='Werte, Fettanteil'] next [wpv-view name='Werte, Fettmasse'] next [wpv-view name='Werte, Fettfreie Masse'] next [wpv-view name='Werte, BMI']" labels="[wpv-view name='Termine']" scaleoverride="true" scalesteps="12" scalestepwidth="5" scalestartvalue="0"]

unfortunately the output of my inner views shortcodes looks like …

wp_charts title="linechart" type="line" align="center" margin="5px 20px" datasets="
55, 54, 54,
next
19.1, 20, 22.2,
next
10.5, 10.8, 11.8,
next
44.5, 43.2, 42.2,
next
23.8, 23.4, 23.2,
" labels=" 02.06.2015, 17.06.2015, 19.08.2015, " scaleoverride="true" scalesteps="12" scalestepwidth="5" scalestartvalue="0"

(that's the output when i remove outer shortcode brackets.)

when i put brackets back on the outer shortcode, the chartgrid is displayed but no lines (and values).

so from my point of view it looks like the linebreaks kill the outer shortcode to display the lines on the chart.

what can /what should i do?

thanks in advance for your help!

best,
s

#342781

a little update that offers a deeper (source code) look and shows about what i am struggeling …

<div id="wpv-view-layout-2491-CPID2484" class="js-wpv-view-layout">

	
	
	55,54,54,
	
	
	
</div>

how can i get rid of that div tag?

is there an equivalent to types field raw output but for the whole view?

best,
s

#342812

Thank you for contacting us here in the Support Forum

In my opinion, the problem is how WordPress resolves ShortCodes and HTML in it, since WP 4.2.3
https://make.wordpress.org/core/2015/07/23/changes-to-the-shortcode-api/

This if you have a View with absolutely NO HTML in it (in the Loop)

I would mean, best here is I get a Duplication of Your Site and try to solve this locally, before we start a long back and forth thread, would you agree?

I would need a sites snapshot if possible.
We usually recommend the free Plugin "Duplicator" for this porpoise.

If you already know how Duplicator works
(http://wordpress.org/plugins/duplicator/),
please skip the following steps and just send me the installer file and the zipped package you downloaded.

★ Duplicator Instructions
hidden link
Send me both files (you probably want to use DropBox, Google Drive, or similar services, as the snapshot file will be quite big)

❌ IMPORTANT ❌
Remember to create or keep an admin account for me before creating the snapshot, or I won't be able to login. You may delete the new admin account once the snapshot has been built.

I will enable your next answer as private so you can provide me the information securely.

Please could you provide me the additional Infos?

Thank you for your patience.

#342835

hej beda.

thanks for your offer and yes i have followed the shortcode dilemma.

though in my case without and even with(!) html code inside the view the div container gets created!

<div id="wpv-view-layout-2491-CPID2484" class="js-wpv-view-layout">

are you sure that this is created by the basic system?

what about …
https://toolset.com/documentation/user-guides/shortcodes-within-shortcodes/
is that still valid?

unfortunately i cannot provide client data en gross.
what i can say is, that it is a very small site and has actually just this few values resulting in those shortcode attribute arrays to build the line chart.

best,
s

#342989

The View div is expected, somehow we need to render the Layout / Parametric Search.

The link you posted is still valid, just, it's thought for adding 3rd party ShortCodes to Views parser, so to use them as nested ShortCodes.

Have you registered the custom ShortCode in Views > Settings > Compatibility > 3rd party ShortCodes?

I would need to somehow reproduce this problem.
Is providing normal access (WP Admin and FTP) also not possible?

What I was thinking is, what does your Plugin expect in the Parameter "datasets"?
If it's expecting JSON as example, you can create it with the View, using a code within the loop as similar to this:

<wpv-loop>[wpv-item index=1]{"value":"[wpv-user field="ID"]","label":"[wpv-user field="user_login"]"}
      
[wpv-item index=other],{"value":"[wpv-user field="ID"]","label":"[wpv-user field="user_login"]"}
</wpv-loop>

(Above is just a example, values and labels can change of course)

Perhaps this helps to achieve your goal.

I will also try to reproduce this situation with the Plugin wp-charts hidden link and see what we can do here.

Please let me know if the above solution works for you, I look forward to your reply!

Thank you for your patience.

#343200

thanks for your help, beda!

i'd like to solve this abstract, if possible:

1.) we do have a shortcode (from any given plugin and have registered this shortcode with views).
2.) we do have custom fields (created/managed with types) that carry values we'd like to work with.
3.) since WP 4.2.3 shortcode nesting ins't allowed in the way we did it before.

now the open points …

4.) how do i build any (most simple) array of my values (WITHOUT any tag or even uncontrolled character arround)?
5.) how can i implement this built array (even perhaps multiple times) in the given shortcode?

as a first approach i would be happy just to comprehend the path i have to take. :o)

best,
s

#343351

Thanks for the Details

In Response to your doubts below:

1.) we do have a shortcode (from any given plugin and have registered this shortcode with views).
OK

2.) we do have custom fields (created/managed with types) that carry values we'd like to work with.
OK

3.) since WP 4.2.3 shortcode nesting ins't allowed in the way we did it before.
We did fix this internally. Our Parser acts earlier, working around most restrictions created by the WP API Update.
That's also why all our ShortCodes work again, and also why you can still nest ShortCodes even if including HTML.

4.) how do i build any (most simple) array of my values (WITHOUT any tag or even uncontrolled character around)?
This is as example possible with the JSON example.
That one can be used as example in a CRED Dropdown and produces values only, not wrapped HTML.

I believe the issue here is that CRED Dropdown as example the small additional HTML (View ID etc) while the 2rd Party plugin's chart can not, as it seems.

Please let me talk to our DEV in order to find out if we can somehow omit this basic minimal HTML.

Please expect my informations here in the forum.

Thank you for your patience.

#343380

OK, I need as much information as possible form your setup.

Perhaps you can share with me:

1. Screenshot of your view
2. Code used (the entire loop, filter, layout, etc)
3. Where and how the view is used.

According to my discussions with the 2nd Tier Supporter it should opposite to what I stated earlier not produce any Default HTML when you render a View.

I am still not sure why this default HTML is produced, and also not sure why it affects your case, but not the by me provided JSON values (this works great and the additional HTML wrappers do not break it)

Can you provide me as much info as possible so I can submit this problem to the 2nd Tier to analyze?

Thank you

#343390

thank you very much beda.

i came up to that i will set up a development copy and will provide admin privileges to you in a short while.

i will come back on that.

best,
s

#343445

beda, could you open a private message for me please!

#343464

Done, next reply is private

Thank you very much for your cooperation

#343860
false syntax.png
Cursor : Write.png
Cursor : Write .png

Thank you

In this Content Template is something wrong.

If you put the cursor somewhere, and delete back or insert space, it performs the action 4 digits later.

I found this issue as I wanted to edit your Content Templates ShortCode, which si wrong, so much is sure.

The SHortCode wp_charts comes from your Plugin, right?
A ShortCode MUST be wrapped in a [ code here ] syntax

Your current code is not, wrapping it in, breaks the front end even more (no ore output)

Additionally you insert the same code in the Page "post=2484&action=edit" again.

Perhaps that's a left over from some tests, but basically, if you call a Post Body in Content Template, you insert the Content you want to display in the Post Body editor.

Otherwise you construct the content in the Content Template and leave the Post Body empty, if you do not call it with shortcode from Content Template-

Anyway, the wp_charts code is surely not in the expected syntax.

Do you have a DOC or somewhat of the plugin, that explains what parameters are allowed, how the syntax shall be, etc?

Then we can make sure the code is correctly written.

You currently get the output "printed and not parsed" because actually this si not a shortcode anymore but simple HTML text. (if not in brackets, it can't execute)

A idea would be, present a simple post with the Plugins default ShortCode and some working values inserted (not using a View)

Then, we can build the correct view for it and solve this issue.

I also suggest to quickly reinstall Toolset, to make sure no corrupt files are installed.

Thank you for your patience.

#343877

hej beda.

sorry for the error in that editor. i saw that when i transferred the content to the page, but was not able to solve it quickly. reinstall of types components did not do the trick, reinstall WP did not do the trick. but finally i found that at least one of the debug tools interacted. so by now the editor is clean again.

i do know that the shortcode will only be processed with square braces! 😉 but if the output is (almost) empty, it's time to have a look at what has been sticked together. by leaving out the outer braces i could give you the source code hints, so … – anyway …

as you recommended i turned the content template off and placed a working shortcode inside the post-content. below are the displayed shortcode and the original from the plugin page inkl. link.

the content template of course still doesn't work even when ich put the braces back on.
please toggle content template on and off an compare the output!

thanks for helping.

best,
s

#344093
Wrong Chart, but rendered View.png
Bad Wizard.png

I have set the View to display all Gewichts-Werte, and the outputted that view to a Post.
It returns 3 values- 54,54,56

I can not find the Post type "Gewichst Werte" in the WP Admin, to control if you really have only 3 such values saved.

Anyway, then I inserted this [wpv-view name="Werte, Gewicht"] to the Custom ShortCode you use, and this is the output:
hidden link

Seems it's rendering fine the values, but the output is not correct, the "chart" is wrong.
(you can see that when you manually enter 54, 54, 55 in the shortcode)

1. Could you check why the "Gewichst Werte" Post is not in the WP Admin menu, and make it available there?

2. I believe you are correct that the JS Class and DIV ID outputted by View is the problem, but I can not yet tell how and if we can remove that.

3. But, there is a major issue we need to fix first.
On above link:
hidden link
==> I was able to see the chart (even if with wrong output)
==> Then, on reload a few times, the chart disappears
==> Are you using some sort of cache plugin?
==> Server side cache?

==> Or is it a known behavior of that Plugin to sometime output data, and sometime not?
I attached a screenshot of what I saw.
Upon edit the View again, with some tests, and reload the page, the Chart is gone and I am not able to bring in back.

I inserted back the original View (yours) with the exact same content as in my test view, and the chart is (now) visible.

4. The Wizard of the View in Post > Edit is also not default.
Something is interfering, and I am not sure what it is.
Do you have any other Plugins installed that interfere?
(see screenshot)

5. BTW, I can also not see the Toolset Plugins in your Plugins list.
Can you send me screenshot of the exact versions you're using?

I set also up a test View and the mentioned test Post.
If possible, can you leave them as is, so I can provide the play ground to the 2nd Tier?

Please could you provide me the additional Infos?

Thank you for your patience.

#344269
Bildschirmfoto 2015-11-03 um 10.31.49.png

dear beda.

i think i did not get all of your points.
my test post hidden link works fine.

1.) i made 'Gewichtswerte' visible in admin.
though in the admin 'Gewichtskurven' seems more relevant to me, as 'Gewichtswerte' is (only) child of 'Gewichtskurven' – as a group of repeating fields.

--
2.) here we go!
can we give that as request to the development team?

--
3.) no cache form my side.
i will check this issue later.

--
4.) it is default! though it's messy. 😉
on enclosed screenshot you can see that views dialogs.css is giving another rule that breaks the view.
to give you best conditions i have corrected this in dev.

--
5.) Types – Version 1.8.8 (updated today)
Views – Version 1.10.1

best,
s

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