Forums › Forums › Search & Filter Pro › Custom post type not showing in "post type" search form UI checkboxes
- This topic has 21 replies, 3 voices, and was last updated 5 years, 3 months ago by Anonymous.
-
Anonymous(Private) August 6, 2019 at 3:52 pm #218238
Hi,
I’m using the download monitor plugin to manage and display WP documents and would like to integrate the related custom post type (dlm_downloads) in a post-type based search form. Basically, the form should display items in the post types posts, events and downloads, along with filters for each one.
My problem is that Download Monitor’s “Downloads” post type shows up just fine under “Search in the following post types” but not under the post type filter.
Any idea of how this could be fixed?
Thanks
Ross Moderator(Private) August 12, 2019 at 1:06 pm #218722Hi again
If you take a look, we have a filter, which will allow you to modify any option in a field (so you will want to remove the first option):
https://searchandfilter.com/documentation/action-filter-reference/#filter-input-objectTake a look at the full featured example to get an idea how to move the options around.
Thanks
Anonymous(Private) August 12, 2019 at 2:11 pm #218732Hmm I’m a bit lost.
What I’m trying to do is not only to remove the all post types filter, but also ensure that one of the selected post types (in my case, press-releases) is selected by default instead in place of the removed filter. I’m not sure how I can use your example to achieve that. Any guidance would be much appreciated.
Anonymous(Private) August 13, 2019 at 10:54 am #218803OK so this is as far as I got:
function filter_input_object($input_object, $sfid) { if(($input_object['name']!='_sf_post_type')||($input_object['type']!='radio')) { return $input_object; } foreach($input_object['options'] as $option) { if($option->value=="") { } else if($option->value=="post") { } } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
All I need now is to assign actions for the ‘if’ and ‘elseif’. But I couldn’t find any example. I would like to hide or delete the option with no value and make the one with value ‘post’ preselected.
Can you help please?
Ross Moderator(Private) August 13, 2019 at 11:52 am #218808Hi Thomas
Because we know the first option is the option we want to remove, we can do it a bit easier like this:
function filter_input_object($input_object, $sfid){ if(($input_object['name']!='_sf_post_type')||($input_object['type']!='radio')) { return $input_object; } if(isset($input_object['options'])){ //remove the first option from the array $removed_option = array_shift($input_object['options']); } return $input_object; } add_filter('sf_input_object_pre', 'filter_input_object', 10, 2);
Now, I’m guessing that this will work (I didn’t test but it looks correct), however, I think next you want the results to be default fitlered by this option?
Thanks
-
AuthorPosts