Hi,
In a custom type archive, there is a custom field textbox, which hook should I use to modify the textbox value before searching?
Hi we have two filters available for processing custom field filter values - one for the original value, and another for the processed value after passing through the check for URL params, shortcode attributes and date functions.:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_custom_field_filter_original_value
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_custom_field_filter_processed_value
Both of those links include code samples if you'd like to see how to use these hooks. Click the orange "+More Usage examples" button to see those samples.
Let me know if you have questions about these, or if I misunderstood what you want to accomplish.
1. Where do I find my view_id? This is my archive, do I use the Toolset->Wordpress Archives->ID?
2. I use the following code, it doesn't work. Where does it go wrong?
3. My website is live. So I create another instance from my backup, then I work from there. Of course they have different IP, but under the archive page, all the custom post isn't displayed. If I click on each post, it was there and show on my screen. But it just don't show any record in the archive page.
function remove_url_tracking( $value, $key, $view_id){
if ( $key == 'wpcf-cf-url' ) {
$pos = strpos($value, '?');
if ($pos > 1) {
$value = substr($value, 0, $pos);
}
//$value = $url_santinized;
}
return $value;
}
add_filter( 'wpv_filter_custom_field_filter_original_value', 'remove_url_tracking', 99, 3 );
1. Where do I find my view_id? This is my archive, do I use the Toolset->Wordpress Archives->ID?
Yes, use the archive ID instead of the View ID.
2. I use the following code, it doesn't work. Where does it go wrong?
If you want to filter the value of the filter text, you should use the second API, wpv_filter_custom_field_filter_processed_value. Check the examples in the documentation. The first API is for a preprocessed value like URL_PARAM(wpcf-cf-url). The second API is for the processed value, like an actual URL.
3. My website is live. So I create another instance from my backup, then I work from there. Of course they have different IP, but under the archive page, all the custom post isn't displayed. If I click on each post, it was there and show on my screen. But it just don't show any record in the archive page.
I'm not sure, can you provide more information?
- Have you resaved your site permalinks?
- Have you tried with a different archive with no filters or custom code? Please create a new WordPress Archive with no Query Filters and temporarily apply this new WordPress Archive to this custom post type. Do the results appear as expected in this new temporary archive?
2. it works now.
3. If I change to an archive which has no filter, it works. And today I use the original archive, it still works.
Thank you.