Hi There!
I am trying to: Display all my posts in the following categories: Annual Accomplishments, Fact sheets, Latest stories, News mentions, Videos. I do not want the other post categories to be displayed in the View output.
Then I would like to have a Frontend Filter so visitors can choose what category to see from the options listed above. The problem is that if I add a filter to only display the categories I want, I can't add a frontend Category filter.
I'm also hoping to remove the Default option that displayed All Posts from the Frontend FIlter and have the Latest Posts category be selected and displayed by default, so perhaps I can just use a Frontend Filter for the Categories and there is a way to hide the categories I don't want to be displayed (Uncategorized, Press releases, and Partner Projects)?
Link to a page where the issue can be seen: hidden link
Thanks so much for your help!
Hello,
Thanks for the details, I can log into your website.
I assume we are talking about the shortcode in post view "Filterable Blog":
[wpv-control-post-taxonomy taxonomy="category" type="select" default_label="All Posts" orderby="count" order="DESC" url_param="wpv-category"]
See our document:
https://toolset.com/documentation/user-guides/views-shortcodes/#wpv-control-post-taxonomy
There aren't such kind of built-in features for both of your requests, they need custom codes, for example, you can use filter hook wpv_filter_query to setup custom PHP function, apply custom taxonomy query to Views, see our document:
https://toolset.com/documentation/programmer-reference/views-filters/#wpv_filter_query
If you need more assistance for it, please provide the FTP access, I need to test and debug it in a live website. Thanks
Thank you for your help.
I'm not familiar with using filter hooks so if you'd be willing to continue helping find a solution, I would greatly appreciate it!
I can clone the site to a staging domain so you can freely make changes. Would a File Manager plugin work instead of FTP access?
Yes, File Manager will work, I have enabled the private message box again.
Thanks Luo Yang!
I have created a copy of the site at dev.pdc.org and installed a File Manager plugin for your use; the login credentials previously created for you should work there as well.
Hope you have a great day!
- Luigi
Thanks for the details, I am checking it in your website, will update here if there is anything found.
I have done below modifications in your website:
1) Edit the post view "Filterable Blog":
hidden link
in section "Search and Pagination", click "JS Editor", setup the JS codes as below:
function specific_terms_func(){
jQuery('[name="wpv-category"] option').not('[value="updates"], [value="accomplishments"], [value="fact-sheets"], [value="in-the-news"], [value="videos-and-media"]').hide();
}
jQuery( document ).on( 'js_event_wpv_parametric_search_form_updated', function( event, data ) {
specific_terms_func();
});
specific_terms_func();
Above JS codes will be able to hide the categories you don't want to be displayed (Uncategorized, Press releases, and Partner Projects)
2) Dashboard-> Toolset-> Settings-> Custom codes:
hidden link
Add/activate a PHP file: filter-results.php
with below codes:
add_filter( 'wpv_filter_query', function($query_args, $view_settings, $view_id){
if($view_id == 243127){
if(!isset($_GET['wpv-category']) || empty($_GET['wpv-category']) ){
$_GET['wpv-category'] = 'updates';
}
}
return $query_args;
} , 10, 3);
Above codes will be able to achieve:
have the Latest Posts category be selected and displayed by default
Please test again, check if it is what you want. Thanks
Thank you for your amazing help!
The Latest Posts category is now successfully being displayed by default, but I'm still seeing the hidden categories when I go to page 2 or later in the results.
And it seems like the Date field is not displaying on the first result of page 2 of the results either, do you know why that may be?
Here is a video: hidden link
I appreciate all your help!
- Luigi
For the question:
but I'm still seeing the hidden categories when I go to page 2 or later in the results.
I have done, below modification in your website:
Edit post view "Filterable Blog":
hidden link
in section "Search and Pagination", click "JS Editor", add below JS codes:
jQuery( document ).on( 'js_event_wpv_pagination_completed', function( event, data ) {
specific_terms_func();
});
Please test again, check if it is fixed.
For the new problem, please check the new thread here:
https://toolset.com/forums/topic/date-field-is-not-displaying-on-the-first-result-of-page-2-of-the-results-either/
My issue is resolved now. Thank you!