Tell us what you are trying to do?
I tried creating a list of upcoming and past events with 2 views and having the posts be grouped into their years, like they are on this page:
hidden link
Unfortunately the shortcode "heading" cannot distinguish between 2 lists on the same page, so the years that are in the list of upcoming events are missing in the list of past events.
Is there any documentation that you are following?
https://toolset.com/forums/topic/use-toolset-to-create-a-list-of-links-for-year-and-month-archive-pages-and-count/
Is there a similar example that we can see?
What is the link to your site?
hidden link
Hello and thank you for contacting Toolset support.
This is most probably caused by the code of the heading shortcode. Somehow it does not handle this case(be used in two lists). Can you share the code of the shortcode in your next reply? Please wrap it inside <code> and </code> tags:
Hi Jamal,
it is exactly the same as in the other topic.
Here it is:
//group by month and year
add_shortcode('heading', 'my_heading');
function my_heading($atts, $content = '') {
static $year = null;
static $month = null;
$condition = $atts['condition'];;
$value = $atts['value'];;
switch ($condition) {
case 'year':
case 'month':
if ($$condition != $value) {
$$condition = $value;
return $content;
}
break;
}
return '';
}
I am sorry, but this is still not clear to me. Would you allow me temporary access to your website to check this closely? Your next reply will be private to let you share credentials safely. ** Make a database backup before sharing credentials. **
Can you also provide more details? What would you expect to have? Keep in mind that I work on several clients' sites per day, and I can't just guess what you want to achieve, your help is very needed.
Indeed, the shortcode is not optimized to handle more than one view on the same page. It uses static variables, and they will always hold the latest value. We can overcome this by updating the code to handle multiple views. For example, using the global variable $WP_Views->current_view(), but that is not really simple, and will need extensive testing.
The easiest solution is to define another shortcode and use it on the 2nd view. I defined another shortcode "heading2" using another function and updated the 2nd view to use it. That produces the expected results.
add_shortcode('heading2', 'my_heading2');
function my_heading2($atts, $content = '') {
static $year = null;
static $month = null;
$condition = $atts['condition'];;
$value = $atts['value'];;
switch ($condition) {
case 'year':
case 'month':
if ($$condition != $value) {
$$condition = $value;
return $content;
}
break;
}
return '';
}
[heading2 condition="year" value="[types field='startdatum' format='Y'][/types]"]
<h2>[types field='startdatum' format='Y'][/types]</h2>
[/heading2]
I hope this helps. Let me know if you have any questions.
My issue is resolved now. Thank you!