Incompatibility between Membership Pro 2 and Key Search Plugin


Preface: I am incurring an Incompatibility between Membership Pro 2 and Key Search Plugin for my site.

This issue has been looked into by the theme developer who successfully demonstrated that this is related to the Membership Pro 2 plugin and not the theme.

Problem: I am incurring problems with the search box on the top right of the primary nav bar.

Please review screencast:

NOTE: If I do a search and type in 27m and wait, the search box will fill with the one post available that is membership protected and if I click on the result it takes me to the post as it should

NOTE: if I however fill out the search field with 27m and click on the magnifying glass it takes me to a results page and this page shows 1 result ( instead of two which you helped me resolve in this ticket: ) but the result is NOT my post. it's a link to the membership page that redirects to the home page.

Note: the search box is also available on this page:

Please refer to these two links:

The link with the capital letters links to the post:

The link with the lower case letters links to

Two scenarios at play here. Only one sequence works and directs me to my protected post.

Theme Developer's reply:

I'm sorry but we have not tested our theme with all third-party plugins.

This problem with plugin => Membership 2 Pro Plugin

If I deactivate this plugin with the search on the site there is no problem.

When I deactivate the plugin to find => 27m => remains 1 post, look at the screenshot

I would appreciate any advice and assistance you may be able to provide to work out a solution. The Membership site is coming together well save for this one essential snag.

  • Sajid

    Hi David,
    Hope you are doing good today :slight_smile:

    This is because you have one post with name SN: 27M6C and membership with similar name SN27M6C .

    The post private and does not appear in search results. Its membership that is listing in the search results page.

    What membership does here is remove the protected posts from archive pages as well as default WordPress search pages.

    In your case you have custom ajax search that comes under the search field. Your custom search does not care if its a protected or not and fetching this post in results where it should not.

    When you hit more magnifying glass its listing the membership with name SN27M6C instead of post. Because Membership knows its a protected post so removes it from search results.

    Okay what you see in instant search is a protected post and what you see in search results page is membership.

    To fix the issue of displaying protected post in instant/ajax search we need to modify the query of custom search. Please ask the theme developer where exactly he is writing the custom query. I will give you code not exclude protected posts from the custom search query.

    For not including the membership in search results, I am bringing this into developers attention so it could be patched up.

    Take care and have a nice day :slight_smile:

    Best Regards,

  • David


    I passed on your question to Theme Support.

    One thing to note. It's worse than that.. If even a part of a work matches it does not work.

    Example: I created another post here:

    I changed the post name to JUST T3C92. I removed "SN:" to the title and remove it from the page url. I kept the membership name "SNT3C92".

    This is like having a membership called ALL and having a page named Baseball and having the membership page being found instead of the post called Baseball because ALL is in the name baseball.

    I shall keep you apprised as things develop but I wanted to point out how significant the problem is.

  • David


    I heard back from the Theme Developer. He posted to me the following files (no notes) to reply to your query. I hope this helps.



    I hope that this is what you requested and that this helps. If you could pleae explain what this is I'd be curious to know.

    I look forward to your reply.

  • Sajid

    Hi David,
    Hope you are doing good today :slight_smile:

    You posted screenshots of the code that would not help me make the changes. Would you please share the actual theme so I can make changes ? If yes then upload the theme zip file (on dropbox, google drive or your own site) and send me the link of that file via our private contact form in following format.

    Subject: "Attn: Sajid Javed”
    - Zip archive download link
    - link back to this thread for reference

    Make sure you select "I have a different question" from dropdown (see screenshot) - this and subject line ensures that it will get assign to me.

    Take care and have a nice day :slight_smile:

    Best Regards,

  • Sajid

    Hi David,
    Hope you are doing good today :slight_smile:

    Thanks for sending in the FTP credentials directly. I downloaded the theme from there and wrote a code snippet to remove the protected items from custom search as well.

    Here is the code, add it in functions.php file of your child theme or use it as mu-plugin.

    function wpmudev_exclude_protected_posts_from_custom_search($args){
    	global $wpdb;
    	$query = "SELECT meta_value
    			  From ".$wpdb->postmeta."
    			  WHERE meta_key = 'rule_values'
    	$get_membership_rules = $wpdb->get_results( $query );
    		foreach ($get_membership_rules as $key => $value) {
    			$rules = unserialize($value->meta_value);
    			if ($rules['post'])
    				foreach ($rules['post'] as $key => $value) {
    					$all_protected_posts[] = $value;
    				//$all_protected_posts[] = $rules['post'];
    			if ($rules['page'])
    				foreach ($rules['page'] as $key => $value) {
    					$all_protected_pages[] = $value;
    		return $args;
    	$all_protected_itmes = array_merge( array_unique($all_protected_pages), array_unique($all_protected_posts));
    	$args['post__not_in'] = $all_protected_itmes;
    	return $args;
    add_filter('ajax_search_query', 'wpmudev_exclude_protected_posts_from_custom_search');

    This will alter the custom query and remove the protected items from results.

    Note: Event though I tested it on my own sandbox site but still don't forge to take full backup of your site before using this code.

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,

  • David


    Thank you for replying. I added your code and an MU plugin but unfortunately it broke the page.

    I added the code to my child theme's functions.php file. It did not break the page but it did not resolve the issue either.

    Please refer to the screen cast:

    This hides the wrong link. To reiterate, I am trying to invite non-members to a protected post that can only be found by doing a search on post title, the post title being the same name as the serial number printed on a token.

    It looks like what has occurred is that the code provided hides the link to the protected post and showcases only the link to the membership which redirects to the home page. (the small cap link).

    To reiterate: The code that's applied to the child theme's functions.php at present does exactly the opposite of what I am requesting in this ticket, it hides the link to the protected post (the ALL CAPS link).

    I really appreciate your assistance on this ticket and look forward to hearing back in regards to correcting the code.

  • Sajid

    Hi David,
    Hope you are doing good today :slight_smile:

    I am sorry for confusion. I have repaced the code given above with following code in functions.php file to include the protected posts in search results and in archive page.

    function remove_protected_posts_from_search_results($wp_query){
    	$wp_query->query_vars['post__not_in'] = array('');
    	return $wp_query;
    add_filter('ms_rule_post_model_protect_posts', 'remove_protected_posts_from_search_results');

    Also, edited the masonay.php file and moved it to your child theme /templates folder to remove the memberships from search page.

    Hope that helps! Feel free to post a reply if you need further assistance :slight_smile:

    Best Regards,