Forums Forums Search & Filter Pro Limiting media search to just PDFs

Viewing 6 posts - 1 through 6 (of 6 total)
  • Anonymous
    #180670

    Is there a way to filter out all media types except for PDFs? I’ve looked around the support forums but haven’t really seen a direct answer. Thank you!!

    Trevor
    #180679

    I think you will need to use our Edit Query Arguments filter to add an extra argument like this:

    'post_mime_type' => 'application/pdf';

    Anonymous
    #180694

    So this is the code block I’d be using?

    
    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 225, the do something with this query
    	if($sfid==225)
    	{
    		//modify $query_args here before returning it
    		$query_args['somearg'] = 'newvalue';
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    
    

    Can you give me any information on how I’d apply your suggestion to this filter? Sorry, I’m not much of a coder.

    Trevor
    #180703

    Yes. The ID number (225) will change to match the ID number of your form, and the code goes inside the functions.php file of your child theme folder.

    You replace this:

    $query_args['somearg'] = 'newvalue';
    

    With:

    $query_args['post_mime_type'] = 'application/pdf';
    
    Anonymous
    #180733

    Trevor, I appreciate the help so far. This is the filter I tried in our functions.php file:

    
    function filter_function_name( $query_args, $sfid ) {
    	
    	//if search form ID = 35922, the do something with this query
    	if($sfid==35922)
    	{
    		//modify $query_args here before returning it
    		$query_args['post_mime_type'] = 'application/pdf';
    	}
    	
    	return $query_args;
    }
    add_filter( 'sf_edit_query_args', 'filter_function_name', 20, 2 );
    

    I got the ID by looking at the query string in the URL on the edit page, as well as verifying it through data-sf-form-id="35922" on the form itself using Chrome inspector.

    For our search page, we’re including posts, pages, and media (trying to only include PDFs from media). After I added this to functions.php, it actually stopped ALL search items from loading.

    Any ideas?

    Trevor
    #180735

    You are searching media post type?

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