I have a filter below from plugin file:
$review_num_fetch = apply_filters('tourmaster_review_num_fetch', 5);
I want change the number from 5 to 3, I’ve tried change it like below:
// reviews number
function tourmaster_review_num_fetch_custom () {
$review_num_fetch = apply_filters('tourmaster_review_num_fetch_custom', 3);
}
remove_filter(‘tourmaster_review_num_fetch’, 10);
add_filter('tourmaster_review_num_fetch', 'tourmaster_review_num_fetch_custom', 10);
But it’s wrong. I’m not sure why, I hope get some explain about it, TIA!
I have a filter below from plugin file:
$review_num_fetch = apply_filters('tourmaster_review_num_fetch', 5);
I want change the number from 5 to 3, I’ve tried change it like below:
// reviews number
function tourmaster_review_num_fetch_custom () {
$review_num_fetch = apply_filters('tourmaster_review_num_fetch_custom', 3);
}
remove_filter(‘tourmaster_review_num_fetch’, 10);
add_filter('tourmaster_review_num_fetch', 'tourmaster_review_num_fetch_custom', 10);
But it’s wrong. I’m not sure why, I hope get some explain about it, TIA!
Share Improve this question asked Jul 1, 2020 at 8:52 Loc_rabbirtLoc_rabbirt 1138 bronze badges 4 |1 Answer
Reset to default 3That's not how filters work. Much like a filter in real life, something goes in, it gets changed, and the result goes out. Filters always take in a parameter and return something. They're an opportunity to change something
So if we take this:
$review_num_fetch = apply_filters('tourmaster_review_num_fetch', 5);
This means the plugin uses 5, but it has given other code an opportunity to change this to another value. It does this by passing it to the tourmaster_review_num_fetch
filter then using the result. So hook into that filter and return a different value to change it.
When that line runs, WP looks at all the filters registered, passes the value, and then replaces it with what the filter returned.
This is what a filter that adds 1 to the value looks like:
function addone( $in ) {
$out = $in + 1;
return $out;
}
And this is how you would add it:
add_filter( 'tourmaster_review_num_fetch', 'addone' );
With that you should have all the knowledge needed for implementing your solution
functions.php
? I see you used backticks iinstead of quotes iin yourremove_filter
call, and you've replaced it with another filter that calls another filter, but you don't seem to have implemented the filters properly, there's basic stuff missing – Tom J Nowell ♦ Commented Jul 1, 2020 at 9:02