Home › Forums › Calendar Products › Filter Bar › Remove and add action to override addQueryArgs for FilterBar
- This topic has 11 replies, 3 voices, and was last updated 10 years, 9 months ago by
Leah.
-
AuthorPosts
-
July 2, 2015 at 4:02 pm #974867
gonzalosanza
ParticipantHello team!
I need to override the function addQueryArgs around line 109 on the-events-calendar-filter-bar/src/Tribe/Filter.php
so, I thought to remove the action on same file, line 88.It means, paste this code on my functions.php
remove_action( ‘tribe_events_pre_get_posts’, array( $this, ‘addQueryArgs’ ), 10 );
add_action( ‘tribe_events_pre_get_posts’, array( $this, ‘addQueryArgsCustom’ ), 10 );function addQueryArgsCustom( $query ) {
if ( ! $query->tribe_is_event ) {
// don’t add the query args to other queries besides events queries
return;
}if ( isset( $_REQUEST[‘tribe_’ . $this->slug] ) && $_REQUEST[‘tribe_’ . $this->slug] != ” ) {
if ( !empty( $this->joinClause ) ) {
add_filter( ‘posts_join’, array( $this, ‘addQueryJoin’ ), 11, 2 );
}
if ( !empty( $this->whereClause ) ) {
add_filter( ‘posts_where’, array( $this, ‘addQueryWhere’ ), 11, 2 );
}
foreach ( $this->queryArgs as $key => $value ) {
$query->set($key, $value);
}
}
}But, it’s not working, probably because I must to use somthing instead $this. I tried with Tribe__Events__Filterbar__Filter::instance() but still nothing.
Any little help please?
Thanks!July 3, 2015 at 7:27 am #975175Nico
MemberHowdy Gonzalo,
Thanks for reaching out! Interesting question here, I’ll try to help you out.
When you remove the action, the first value in the array should be a string with class name and the second one point to the method in that function. Now, when you add your own action, as you are using a custom function that’s not inside the class you should just input the function name there.
remove_action( 'tribe_events_pre_get_posts', array( 'Tribe__Events__Filterbar__Filter', 'addQueryArgs' ), 10 );
add_action( 'tribe_events_pre_get_posts', 'addQueryArgsCustom', 10 );function addQueryArgsCustom( $query ) {
//your code
}
Please give this a try and let me know how it goes,
Best,
NicoJuly 6, 2015 at 8:15 am #976145gonzalosanza
ParticipantReally thanks Nico! your code seems to work! but im still having problem using $this inside the function addQueryArgsCustom. I also tried with Tribe__Events__Filterbar__Filter::instance() but doesn’t works.
Any idea? Thanks!July 7, 2015 at 2:20 pm #984574Nico
MemberGonzalo,
Sorry to say I wasn’t looking at the code inside your function, lazy me 🙁
I get what you are trying to do there, tried a couple of things to get the instance there but had no luck with that. I’ll ping someone in the dev team to give me a hand on this. I’ll get back to you as soon as I have a answer for this.
Best,
NicoJuly 8, 2015 at 7:08 am #984741Nico
MemberHey Gonza,
It would be great to know what you are trying to achieve there! The custom function you are using to replace ours with is actually identical to ours. Knowing this might help us find a way to solve this. Solution might not be as straightforward as unhooking and re-hooking that action.
Thanks for your patience on this,
NicoJuly 8, 2015 at 8:30 am #984792gonzalosanza
ParticipantThanks Nico! It make sense!
I have some custom filters on filter bar, based on the filter category. To make theme work propperly, I had to override the addQueryArgs function to this one (It’s very similar to the original, thats way I paste the original on the bigining, sorry):public function addQueryArgs( $query ) { if ( ! $query->tribe_is_event ) { // don't add the query args to other queries besides events queries return; } if ( isset( $_REQUEST['tribe_' . $this->slug] ) && $_REQUEST['tribe_' . $this->slug] != '' ) { if ( !empty( $this->joinClause ) ) { add_filter( 'posts_join', array( $this, 'addQueryJoin' ), 11, 2 ); } if ( !empty( $this->whereClause ) ) { add_filter( 'posts_where', array( $this, 'addQueryWhere' ), 11, 2 ); } foreach ( $this->queryArgs as $key => $value ) { if($key=='tax_query'){ $taxquery=$query->get('tax_query'); if($taxquery!=null){ foreach($value as $v){ array_push($taxquery,$v); } }else{ $taxquery=$value; } } $query->set($key, $taxquery); } } }It works, but If I update the plugin… Thats way I would like to unhook, rehook if its possible.
Really thanks for your time!!
-
This reply was modified 10 years, 9 months ago by
gonzalosanza.
July 9, 2015 at 10:46 am #985135Nico
MemberGonza,
Thanks for the follow-up! Nice piece of code I have to say.
I’ve check your code with the dev team, and the thing is there is no better -‘more sustainable’- way of doing that at the time 🙁
The good thing is that per dev suggestion I added this as a feature request and a filter to achieve this will be -probably- included in our code. Not sure if it will make it to upcoming release, but I’ll try to push it forward.Please be sure to check release note for upcoming version of FilterBar, to see if this is included. I’ll try to have this on my radar and let you know as well.
At this point I’m suspecting you speak Spanish, please let me know if you do.
Best,
NicoJuly 16, 2015 at 4:03 am #986915gonzalosanza
ParticipantOK Nico, thanks anyway for your help!
Yes! I speak spanish!
Regards!July 16, 2015 at 7:06 am #986977Nico
MemberBuenísimo Gonza, voy a estar pendiente a este cambio entonces. Cuando este implementado te aviso por e-mail (a la dirección que figura en tu usuario).
Te parece bien si cierro esta conversación Si surge alguna duda relacionada siempre podes abrir una nueva y linkear a esta como referencia.
Lamento que no haya otra forma de resolverlo por ahora, gracias por la paciencia!
Saludos,
NicoJuly 16, 2015 at 7:10 am #986980gonzalosanza
ParticipantOK, ningún problema, cierra la conversación. Como dices, agradecería si me notificas por email si hay alguna novedad.
Gracias!
Un saludo!July 17, 2015 at 2:17 pm #987498Nico
MemberGonza,
Me comprometo a hacerlo!
Saludos,
Buen finde,
NicoJuly 20, 2015 at 1:28 pm #988114Leah
MemberHi there,
We wanted to check in here and update you on our progress. Although we weren’t able to address your issue in our upcoming release (3.11) we do still have it on our radar. Thank you for your patience while we continue working on a fix for the problem you reported. We will do our best to keep you posted when we have a solution in place. In the meantime, if you need help or find that the issue you reported here is no longer a problem, please feel free to start another thread.
Thanks again for your patience and understanding!
Cheers,
Leah
and the rest of The Events Calendar team -
This reply was modified 10 years, 9 months ago by
-
AuthorPosts
- The topic ‘Remove and add action to override addQueryArgs for FilterBar’ is closed to new replies.
