I am trying to: display a variable that I've passed to a view by shortcode
I followed the steps in this post: https://toolset.com/forums/topic/pass-variable-argument-to-a-view-to-query-filter-shortcode-of-a-2nd-view/
My function is:
add_shortcode('wpv-view-shortcode-attribute', 'wpv_view_shortcode_attribute');
function wpv_view_shortcode_attribute($atts) {
global $WP_Views;
$attributes = reset($WP_Views->view_shortcode_attributes);
return $attributes[$atts['attribute']];
}
I'm calling my second view from my first using:
[wpv-view name="items-for-market" wpvprchildof="[wpv-post-id id=$market]" this_promo_market='[wpv-post-title id=$market]']
In my "items-for-market" view, I'm attempting to simply display that variable using:
[wpv-view-shortcode-attribute attribute="this_promo_market"]
I have also tried displaying other shortcode variable using:
[wpv-view-shortcode-attribute attribute="wpvprchildof"]
I made sure to add my shortcode to the Views settings per the post above, but I cannot get any value to simply display.
Please help.
The other thread talks about passing a ShortCode argument to a View as a variable defined in a ShortCode.
Where do you pass the ShortCode in your View #2?
I do not see this in your code.
The Thread you link to is using a $variable to populate the ShortCode argument.
You use a static variable in the ShortCode argument.
Can you try top populate it with [your_shortcode_that_generates_the_variable]?
Thank you
Hi Beda. I should have made that clearer. View #1 is "market_for_sales_rep". View #2 is " items-for-market"
From view #1; market_for_sales_rep, I'm loading view #2 with [wpv-view name="items-for-market" wpvprchildof="[wpv-post-id id=$market]" this_promo_market='[wpv-post-title id=$market]']
I have assigned the variable 'this_promo-market' a value of '[wpv-post-title id=$market]' in the shortcode.
Then, in view #2, I'm attempting to display that variable with [wpv-view-shortcode-attribute attribute="this_promo_market"] but its not displaying anything.
I even tried to use the same function to just display the value of the first variable being passed in the view shortcode; wpvprchildof="[wpv-post-id id=$market]", by using [wpv-view-shortcode-attribute attribute="wpvprchildof"], just to see if I could display a passed variable that appears to be working, and that did not display anything either.
I guess I'm trying to figure out some general way to reliably pass and use variables from view to view.
I will need to login to this site and see the setup life if possible.
Meanwhile can you also try:
[wpv-attribute name="this_promo_market"]
If that doesn't work, I would 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 and check if some configurations might need to be changed
Your next answer will be private which means only you and I have access to it.
❌ Please backup your database and website ❌
✙ I would, if possible, need access to a site where only a minimal set of Plugins and a default theme is active.
This to avoid eventual compatibility issues with other software.
✙ I would additionally need your permission to de- and re-activate Plugins and the Theme, and to change configurations on the site.
This is also a reason the backup is really important
✙ Please add the Links to:
- The Views Edit Screen
- The Page/Post where you insert the View
- The corresponding Front End Page/Screen
- Please add a detailed desctrpion along with the links, how things are supposed to work.
Thank you