Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Forums Forums Search & Filter Pro Set "selected" when using the sf_input_object_pre hook to alter select field?

Viewing 3 posts - 1 through 3 (of 3 total)
  • dpolonsky
    #215860

    Hi,

    I’m using the sf_input_object_pre hook to edit the post type select field in the search form – which works great! I’ve used it to combine post types, for example, people who use my site don’t know the difference between posts and pages, they know them all as “Articles” – so I re-labeled “Posts” as “Articles” and changed the value where the post types get passed as “post,page”. And then I unset the Page option so there wouldn’t be duplication.

    This works fine, however, since I’m combining post types, the “selected” value that shows once the form is submitted does not show. So “Articles” won’t stay selected after the results are filtered, I guess because the select field is probably just checking one post type against one post type where I’m now passing two. Is it possible to achieve this with the filter hook I’m using? Here is what my function looks like:

    function customize_post_type_filter( $input_object, $sfid ) {
    		if ( $input_object['name'] == '_sf_post_type' ) {
    			//update this field before rendering
    			if ( isset( $input_object['options'] ) ) {
    				foreach ( $input_object['options'] as $option ) {
    					//combine posts and pages option
    					if ( $option->label === 'Posts' ) {
    						$option->label = 'Articles';
    						$option->value = 'post,page';
    					}
    				}
    
    				unset( $input_object['options'][2] );
    				
    			}
    		}
    
    		return $input_object;
    	}

    Thanks!

    Trevor Moderator
    #215867

    I do not think you can do this using that filter, sorry.

    dpolonsky
    #215875

    Ok, thank you for confirming. I think I’ll just add a snippet of JS where I can pass a value from the PHP and if the post type is what I’m looking for, I can set the value with JS as a “hack” for now. Since I’m not using ajax for the form and the form has to be submitted to filter results, it should work okay. Thanks!

Viewing 3 posts - 1 through 3 (of 3 total)

The topic ‘Set "selected" when using the sf_input_object_pre hook to alter select field?’ is closed to new replies.