Skip Navigation

[Resolved] Filtering by year – with multiple &view_id’s

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

Problem:

I need another View ID to work with the PHP script - so I will need an array for this variable?

Solution:

You can try PHP function in_array(), for example:

https://toolset.com/forums/topic/filtering-by-year-with-multiple-view_ids/#post-1229217

Relevant Documentation:

https://www.php.net/in_array

This support ticket is created 5 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.

Sun Mon Tue Wed Thu Fri Sat
- 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9:00 – 13:00 9: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/Hong_Kong (GMT+08:00)

This topic contains 4 replies, has 2 voices.

Last updated by michaelM-30 5 years, 7 months ago.

Assisted by: Luo Yang.

Author
Posts
#1229205

I am using this toolset script for filtering my post by year (which works perfect)

This is the part in the functions.php:
// Toolset Filterung nach Jahr - siehe https://toolset.com/forums/topic/create-a-filter-to-show-news-by-year/
function year_func( $query_args, $settings, $view_id ) {
if ( $view_id == 7141 && isset($_GET['wpv-year'][0]) && !empty($_GET['wpv-year'][0]) ) {
$star_date = strtotime("01/01/" . $_GET['wpv-year'][0]);
$end_date = strtotime("01/01/" . ($_GET['wpv-year'][0] + 1));
$query_args['meta_query'] = array(
array(
'key' => 'wpcf-date',
'value' => array($star_date, $end_date),
'compare' => 'BETWEEN',
),
);
}
return $query_args;

}

My problem is, that I need another View ID to work with this script - so I will need an array for this variable?
But I do not know how to do this.
So basically I have two View Id's on which this script has to work
7141 and 1742.

Can you help me with the correct code for this?

Many thanks
Michael

#1229211

Hello,

You can try PHP function in_array(), for example, replace this line from:

if ( $view_id == 7141 && isset($_GET['wpv-year'][0]) && !empty($_GET['wpv-year'][0]) ) {

To:

if ( in_array($view_id, array(7141, 1742) && isset($_GET['wpv-year'][0]) && !empty($_GET['wpv-year'][0]) ) {

More help:
hidden link

#1229214

Hello Luo, thanks for the code,
but I get the following error:

Parse error: syntax error, unexpected ';' in /www/htdocs/w0151afe/history.frame3d.info/wp-content/themes/colormag-child/functions.php on line 245

when using your code.

#1229217

You are right, please replace that line to:

if ( in_array($view_id, array(7141, 1742)) && isset($_GET['wpv-year'][0]) && !empty($_GET['wpv-year'][0]) ) {

And test again

#1229229

Perfect!
My issue is resolved now. Thank you!