Skip Navigation

[Resolved] Filter taxonomy view by date

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

Problem:
Filter taxonomy view by date

Solution:
To filter the taxonomy view, you will require to use the view's filter hook: wpv_filter_taxonomy_query

You can find proposed solution in this case with the following reply:
=> https://toolset.com/forums/topic/filter-taxonomy-view-by-date/#post-2072571

Relevant Documentation:
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

This support ticket is created 3 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
- 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10:00 – 13:00 10: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/Kolkata (GMT+05:30)

This topic contains 6 replies, has 2 voices.

Last updated by poM 3 years, 7 months ago.

Assisted by: Minesh.

Author
Posts
#2070341

poM

Tell us what you are trying to do?

I have a taxonomy view that embeds a Woocommerce products view filtered by the parent taxonomy term.

This taxonomy is a product attribute and terms are Unix timestamps.

I would like to show only the terms greater than today.

Is there any documentation that you are following?

Is there a similar example that we can see?

What is the link to your site?

hidden link

#2071225

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Hello. Thank you for contacting the Toolset support.

I've to review you structure and where on what page you have added the view and what view you want to filter?

Can you please share all those require information that should help me to understand your issue and once I review your setup I will be able to guide you in the right direction.

*** Please make a FULL BACKUP of your database and website.***
I would also eventually 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.

I have set the next reply to private which means only you and I have access to it.

#2071273

poM

This should be done with custom code and wpv_filter_taxonomy_query filter but I don't know how.

#2072409

poM

Hi,

So any news about my request ?

Cheers.

#2072547

poM

Hi,

Website is broken, I get :

Array
(
[hide_empty] => 1
[hierarchical] => 1
[pad_counts] => 1
[orderby] => name
[order] => ASC
[include] => Array
(
[132] => 132
[127] => 127
[125] => 125
[134] => 134
)

)

Plese try to avoid breaking things, I am actively working on this site.

#2072555

Minesh
Supporter

Languages: English (English )

Timezone: Asia/Kolkata (GMT+05:30)

Actually I was testing the shortcode I build.

To filter the taxonomy view, you will require to use the view's filter hook: wpv_filter_taxonomy_query
=> https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_taxonomy_query

To get only the term IDs of future date, you will require to write some custom code for example:

$all_terms = get_terms( 'pa_jours-affichage', array(
    'hide_empty' => false,) );

$include = array();
foreach($all_terms  as $k=>$v):
       if($v->name > time()){
          $include[$v->term_id] = $v->term_id;
       }
endforeach;

So you should hook in the found term IDs in $include variable those are the terms greater than the current time.

#2072571

poM

Hi,

Thanks a lot for your precious help.

Finally works wi the following code :

add_filter( 'wpv_filter_taxonomy_query', 'exclude_specific_terms_func', 99, 3 );

function exclude_specific_terms_func( $tax_query_settings, $view_settings, $view_id ) {

if ( 49713 == $view_id || 49756 == $view_id ) {

$all_terms = get_terms( 'pa_jours-affichage', array('hide_empty' => false,) );

$exclude = array();
$current_time = current_time( 'timestamp');
$tomorrow = strtotime('tomorrow');

foreach($all_terms as $k=>$v):

if( intval($v->name) < $tomorrow ){
$exclude[$v->term_id] = $v->term_id;
}

endforeach;
$tax_query_settings['exclude'] = $exclude;

}
return $tax_query_settings;

}