Support Forums

Support Forums Forums Search & Filter Pro Custom post type not showing in "post type" search form UI checkboxes

This topic is: resolved

This topic contains 21 replies, has 3 voices, and was last updated by  Thomas 1 week, 1 day ago.

Viewing 10 posts - 11 through 20 (of 22 total)
  • Thomas
    #218850

    Thanks Ross. Yes that’s right, your code works but I still need the results to be default filtered with the “post” value.

    How can I do that?

    Ross Moderator
    #218958

    Hi again.

    So the absolute easiest way to do this, is perform a search, and then look at the URL:

    mysite.com/?sf_myoption=myvalue

    Then you can link to this URL from your navigation or wherever you are using a link to the search page, with the URL value in there.

    Because you’ve removed the first option too, the search form can appear within the site without the worry of an option not being selected before being used.

    There is another more tedious way of modifying the query with another filter – though, we’re improving this for v3 (our next major release) so the above option might be simpler for now.

    Let me know your thoughts.

    Thanks

    Thomas
    #218966
    This reply has been marked as private.
    Ross Moderator
    #218979

    Ahhh yes fair enough, if it wasn’t the homepage the above should have worked, but in this scenario I can see why that wouldn’t.

    Anyway, I’ve had a little play with some code and this is working for me (where your homepage page ID is 2) – add this in addition to the code before:

    add_action("init", "wp_init");
    function wp_init(){
    	
    	//make sure this the homepage only, you might need to adapt this (start by removing if this is not working)
    	if(is_page(2)){
    		
    		//if post types is not set, set it to 'post;
    		if(!isset($_GET['post_types'])){
    			$_GET['post_types'] = 'post';
    		}
    	}
    }

    It’s a little hacky but seems to work just fine in my testing.

    Thanks

    Thomas
    #218987

    Thanks, is this to be added to the previous filter function, or as an entirely different function as you have it in your message?

    Thomas
    #218989

    I’m asking because copying and pasting it as such in functions.php doesn’t do anything 🙂

    Thomas
    #218991

    Ok well, it works if I remove the if is_page part.

    I understand this won’t affect search forms where the filter has not been removed so that should work fine.

    Thanks for the great support, as usual!

    Thomas
    #218993
    This reply has been marked as private.
    Thomas
    #219115

    Hi Ross,

    Have you had a chance to consider what could be the issue here? As explained, your code breaks other search forms by causing them to query posts instead of the cpt defined in admin.

    Thanks,

    Ross Moderator
    #219133
    This reply has been marked as private.
Viewing 10 posts - 11 through 20 (of 22 total)

The topic ‘Custom post type not showing in "post type" search form UI checkboxes’ is closed to new replies.