Support

Search results for ""

Sorry, no results found. Perhaps you would like to search the documentation?
All Topics
daniel.bichler

Search plugin adds parameter which disables Admin Columns filter search

Hello,

I use the Admin Columns Pro plugin in combination with the Advanced Custom Fields (ACF) Pro plugin. On my custom post type overview page I included many ACF columns. The filter work perfectly. As soon as I use the post search form on the custom post type overview page no results show up anymore. The plugin I use for search is “Search Everything”, because it is the only plugin which searches through all ACF fields. I noticed that s=searchparameter is added to the URL, which seems to cause the trouble. If I remove this term the Admin Columns filter adjustments work just fine again.

Is there any solution that the Search Everything plugin and the Admin Columns Filter search work together? And if not can you recommend a handy workaround using PHP or JavaScript?

Thanks!

3 years, 8 months ago
Stefan
Developer

Hi Daniel,

I tried some things with the “Search Anything” plugin and will describe my foundings below.

The search plugin returns 0 results when you hit the search button without typing any search terms. This also happens when you disable our plugin. I believe this is a bug in the search everything plugin. It even gives some SQL errors when I hit the search button without any search terms.

When I activate our plugin and go to the search page, I see all records. As soon as I filter on any field/column and hit the filter button (or search, they both do the same), I’ll get no results. The reason for this is because the search field is also posted in this request as empty ( ?s= ). This results in the same behavior as described above.

Now I filter on a custom field column on the value ‘stefan’ (which should return a result) and also put in the search term ‘stefan’ in the search box and hit Search/filter. Now I have one post that contains ‘stefan’ in my post. This means both plugins do work together as long as there is a search term provided.

But keep in mind that both filtering and search work together as an ‘AND’ operator. This means that only records with filter value ‘X’ and search value ‘Y’ in the same posts are found.

Are you sure you use the search feature to narrow down the results that are already filtered by our selection? Could you also have a look if you have sorting active on any column? Look for the ‘reset sorting’ button on top of your screen and hit it and try again. By default when sorting is active, records with no value are not shown in the overview.

Now about a possible solution. I believe the only problem here is the empty s param in the URL. You could write a redirect and remove the empty ‘s’ param from the URL if this param is empty. Of course, better would be that the search everything plugin does nothing when the search param is empty. You could write a bug report for this on their support forum. Other than this, there is not much we can do on our side to help you further with this problem.

3 years, 8 months ago
daniel.bichler

Thank you for your support, Stefan! I’ve already assumed that a redirect might be the only solution :( If anyone is interested, thats a workaround, which seems to work for me:

function have_posts_override(){  
        global $wp_query;
        global $current_screen;
		if($current_screen->post_type == 'XXX'){
        	$count_post_edit = $wp_query->post_count;
            ?>
            <script type='text/javascript'>
            	function removeParam(key, sourceURL) {
				    var rtn = sourceURL.split("?")[0],
				        param,
				        params_arr = [],
				        queryString = (sourceURL.indexOf("?") !== -1) ? sourceURL.split("?")[1] : "";
				    if (queryString !== "") {
				        params_arr = queryString.split("&");
				        for (var i = params_arr.length - 1; i >= 0; i -= 1) {
				            param = params_arr[i].split("=")[0];
				            if (param === key) {
				                params_arr.splice(i, 1);
				            }
				        }
				        rtn = rtn + "?" + params_arr.join("&");
				    }
				    return rtn;
				  }
            	var count_post = '<?php echo $count_post_edit;?>';
            	if(count_post == 0 && window.location.href.indexOf("s&") > -1){
            		var url_new = removeParam("s", window.location.href);
             		location.href = url_new;
            	}
          	</script>
          <?php
      
    	}
}
add_action('admin_head', 'have_posts_override' );
3 years, 7 months ago
Stefan
Developer

Thanks for sharing Daniel.
Although I would write it only in PHP instead of including some JS.
You can use the following snippet if you like.

/**
 * @param WP_Screen $current_screen
 */
function acp_remove_empty_search_param( $current_screen ) {

	// Only run this hook on the WordPress admin pages
	if ( ! is_admin() ) {
		return;
	}

	// Do post type check if necessary
	if ( 'post' !== $current_screen->post_type ) {
		return;
	}

	if ( isset( $_REQUEST['s'] ) && ! $_REQUEST['s'] ) {
		wp_redirect( remove_query_arg( 's' ) );
		exit;
	}

}

add_action( 'current_screen', 'acp_remove_empty_search_param' );
3 years, 7 months ago

You must be logged in to reply to this topic.