Zip code seach in Multisite Network

Hello all, hope everyone is doing dandy

We have been developing a tutoring website for a local Tutoring Club that has multiple locations on the west coast.

They would like to have a zip code search dialogue in the top header that will list the closest locations on the user's zip entry. They only have a couple locations so this would not be a huge search query.

I have already started the custom top-header, now I need to add the "Find my Location" section to the right of the phone number.

I found the Global Site Search in combination with the Post Indexer, and I believe this is how we can achieve a network search function.

Seems pretty simple
1) set up the zip code search
2) get the custom code so I can add it to the header.

But I am unfamiliar with search functions, so I might need a little guidance. . .

Thanks for reading! And thanks for your feedback!
-Luke

  • James Morris

    Hello Luke,

    I hope you are well today. Thank you for your question.

    I've put together a little proof of concept to show how this can be accomplished.

    • Attached you will find a simple mu-plugin. This registers a custom post type that only has a title. Simply upload this into your wp-content/mu-plugins/ folder on your multi-site install. This will register the Zip Code post type for all network sites.
    • Install Post Indexer and set it to only index the "zip" post type.
    • Install Global Search and set it to only search the "zip" post type.
    • Add the Global Search widget to your sidebar.
    • Post some Zip Codes in your sub-sites.
    • Test

    See the following thread on how to add Global Search to your theme files: https://premium.wpmudev.org/forums/topic/how-do-i-add-a-global-search-form-to-the-header

    Let me know if you have any further questions. I'll be happy to help!

    Best regards,

    James Morris

  • Luke

    Hi James, thanks so much for helping us out with this!

    Everything looks great! I was able to place the code for the header widget. Thank you!

    But the zip-code-post-type.zip is having trouble uploading to wp-content/mu-plugins/ folder.

    Here is the filezilla error log:

    If I need to complete something special to gain access to the mu-plugins/ folder, let me know.

    Thanks again for your expert advice
    -Luke

  • James Morris

    Hello Luke,

    I hope you are well today.

    By the looks of things, the permissions on your mu-plugins folder is not correct. I recommend taking a look at the following article which does a very good job at explaining file system permissions and how to change them. You'll want your mu-plugins directory set to 755.

    Understanding File Permissions and Using Them to Secure Your Site: https://premium.wpmudev.org/blog/understanding-file-permissions/

    Now, once you get your folder permissions set correctly, you'll want to extract the file that's inside the zip archive before you upload it to your server. The file you'll want to upload is zip-code-post-type.php. Once this file is uploaded, it will automatically be activated and will be ready to use.

    Let me know if you have any further questions. I'll be happy to help!

    Best regards,

    James Morris

  • James Morris

    Hello Luke,

    When I attempted to access your site, I was presented with a IIS 404 page, so I'm unable to give you the exact code needed to do this. However, the following solutions should work.

    To modify the form to have placeholder text, you would simply need to add the following to the input element:

    <input type="search" class="search-field" placeholder="Locate a Club" value="" name="search">

    As far as adding the search icon, that will depend on the theme. Some themes have this ability built in, but if yours does not, the following article may prove to be useful.

    http://stackoverflow.com/questions/18838964/add-bootstrap-glyphicon-to-input-box

    Let me know if you have any further questions. I'll be happy to help!

    Best regards,

    James Morris

  • Luke

    Thanks so much for helping us out with this James! The stack overflow input box link worked like a dream. Although I'm having some css styling issues with the bottom border eek! Otherwise it looks great!!

    I have tested the search function and it always seems to bring up blank results. If you would like access to our backend, please let me know.

    Thanks so much for your excellent help!
    -Luke

  • James Morris

    Hello Luke,

    I have tested the search function and it always seems to bring up blank results. If you would like access to our backend, please let me know.

    When I tested this on a fresh install it worked well. Have you tried testing it with the Global Search widget to ensure that the problem isn't isolated to your custom search form in the header?

    When I attempted to access your site, I was presented with a IIS 404 page, so I'm unable to take a closer look. If you want to grant me direct access to your wp-admin, please follow these steps:

    Please visit the Contact page and complete the form with the following information:

    Select "I have a different question" from the drop-down box.

    Subject: "Attn: James Morris"

    In the Message box, please provide the following:

    - Admin login:
    Admin username
    Admin password
    Login url

    - Domain Registrar Login
    Admin username
    Admin password
    Login url

    - Hosting Control Panel Login
    Admin username
    Admin password
    Login url

    - FTP credentials
    host
    username
    password
    (and port if required)

    - link back to this thread for reference
    - any other relevant urls

    Best regards,

    James Morris

  • Luke

    Hi James, thanks again for your assistance. Very useful and I'm learning great things!

    The styling on the search box is no big deal, I fixed it.

    I just want to be sure the code rearrangement I made on the global search plugin didn't break it

    <?php global $current_blog ?>
    <form action="<?php echo esc_url( trailingslashit( $current_blog->path . global_site_search_get_search_base() ) ) ?>">
    <table border="0" cellpadding="2" cellspacing="2" style="width:100%">
    <tr>
    <td class="inner-addon left-addon" style="width:80%">
    <!-- MY CODE -->
    <i class="fa fa-search"></i>
    <input type="search" class="search-field" placeholder="Locate a Club" value="" name="search">
    <!-- MY CODE END -->
    <!-- ORIGINAL CODE -->
    <!-- <input type="text" value="Locate a Club" name="phrase" style="width:100%" value="<?php echo esc_attr( stripslashes( global_site_search_get_phrase() ) ) ?>"> -->
    </td>
    <td style="text-align:right;width:20%">
    <!-- ORIGINAL CODE -->
    <!-- <input type="submit" value="<?php _e( 'Search', 'globalsitesearch' ) ?>"> -->

    </td>
    </tr>
    </table>
    </form>

    I would like the icon to be clickable as well.

    Thanks for your help!
    -Luke

  • James Morris

    Hello Luke,

    I hope you are well today.

    Yes, the code you posted won't quite work. Mainly because you're missing the following in your input value:

    <?php echo esc_attr( stripslashes( global_site_search_get_phrase() ) ) ?>

    I just tested this code out on my dev site and it seems to work well:

    <?php global $current_blog ?>
    <form action="<?php echo esc_url( trailingslashit( $current_blog->path . global_site_search_get_search_base() ) ) ?>">
    	<table border="0" cellpadding="2" cellspacing="2" style="width:100%">
    		<tr>
    			<td class="inner-addon left-addon" style="width:80%">
    				<i class="fa fa-search"></i>
    				<input type="text" name="phrase" placeholder="Locate Club" style="width:100%" value="<?php echo esc_attr( stripslashes( global_site_search_get_phrase() ) ) ?>">
    			</td>
    			<!--<td style="text-align:right;width:20%">
    				<input type="submit" value="<?php _e( 'Search', 'globalsitesearch' ) ?>">
    			</td>-->
    		</tr>
    	</table>
    </form>

    As far as making your search icon clickable, you may want to take a look at this thread on stackoverflow.

    http://stackoverflow.com/questions/6933941/clickable-icon-inside-input-field

    I hope this helps clarify things a bit.

    Best regards,

    James Morris

  • Luke

    Hello again James, I just tested the functionality of the search.

    • I added a zip to the Test Clone site (90034)
    • I used the zip I added (90034) in both the header search and the individual page search.

    But no search results appeared

    Here is my final coding ( I placed both "input" elements in the <td>.

    <td class="inner-addon left-addon" style="width:80%">
    <input type="text" name="phrase" placeholder="Locate A Club" style="width:100%" value="<?php echo esc_attr( stripslashes( global_site_search_get_phrase() ) ) ?>">
    <input type="submit" value="<?php _e( 'Search', 'globalsitesearch' ) ?>">

    </td>

    Maybe I need to further configure the Global Site Search plugin, or the Zip code search plugin?

    Thanks!
    -Luke

  • James Morris

    Hello Luke,

    First, could you try backing up and removing your code and pasting this code exactly as it is below?

    <?php global $current_blog ?>
    <form action="<?php echo esc_url( trailingslashit( $current_blog->path . global_site_search_get_search_base() ) ) ?>">
    	<table border="0" cellpadding="2" cellspacing="2" style="width:100%">
    		<tr>
    			<td class="inner-addon left-addon" style="width:80%">
    				<input type="text" name="phrase" placeholder="Locate A Club" style="width:100%" value="<?php echo esc_attr( stripslashes( global_site_search_get_phrase() ) ) ?>">
    				<input type="submit" value="<?php _e( 'Search', 'globalsitesearch' ) ?>">
    			</td>
    		</tr>
    	</table>
    </form>

    I've looked through your setting again and they are the exact same as what I have on my test site. The only difference is I'm using the default widget and you are customizing yours.

    If the above code snippet doesn't work, for testing purposes, could you backup and remove your custom code and just enable the native global search form widget and see if it works? If it does, that eliminates global search and the problem is in the custom code.

    Best regards,

    James Morris

  • Luke

    Hi James!
    Hope you had a pleasant weekend

    For an update on my testing with the Global Search Plugin. . .I went ahead and replaced the code you requested:

    . . . I checked the settings on the global search plugin (its set to search for zip):

    I also wanted to check the Indexer, looks like its functioning:

    Our Test Clone site has been given a zip code:

    But on a search from the top-bar it returns no results:

    . . . the same happens when we enter the zip on the page above.

    I also enabled the Global Search Widget on the footer:

    [image pos="5"]
    . . . but this also returns no search results. . .

    Let me know what next steps we should take.

    Thanks again for your help,
    Luke

  • James Morris

    Hello Luke,

    Unfortunately, I'm having a very difficult time reproducing your symptoms. I've tested what I've suggested to you on several PHP versions ranging from 5.2.17 to 7.0.11. This also includes using custom templates in the theme. I've also asked another Staff member to test as well. All were fresh installs of WordPress with only the required plugins installed. On all our installs, we've been able to get this to work.

    So, this leads me to believe there is some kind of conflict on your site that's preventing this for working for you. Would you please run a plugin/theme conflict check to see if that resolves your issue?

    Please see the following article to learn how to perform a plugin/theme conflict check: https://premium.wpmudev.org/manuals/using-wpmu-dev/getting-support/

    Best regards,

    James Morris

  • Luke

    Hi James, hope you're having a great week!

    I had the chance to deactivate all the plugins and test if the global search would indeed work.

    The only plugins I had "Network Activated": Global Site Search, Post Indexer & WPMU DEV.

    The zip search did not work. So I decided to be sure all of my elements are set up correctly. . .Global Site Search & Post Indexer are working:

    Using the default code you sent me for the global-site-search-form.php file

    The child theme functions.php file has the search bar code added:

    And the appropriate header (the chosen header from our theme) file (in the child theme) has the requested code added:

    [image pos="5"]

    But we are still getting no results

    [image pos="6"]

    I want to make sure I am adding the code in the right files:

    The header is located in: lms-child > framework > header3.php
    The global-site-search.php is in: lms-child folder
    The functions.php file I am adding code is in the lms-child theme folder.

    Should we test it on the parent theme? I am running out of ideas.

    . . .but as always, I know we can get it to work Let me know what you need?

    Thanks for your excellent advice
    -Luke

  • James Morris

    Hello Luke,

    I'm not seeing any reason why this should not work.

    Can you try commenting out your custom code in your child theme and backing up and removing your custom templates related to Global Site Search and just try the native widget that ships with the plugin?

    I know this widget won't work for production, but if we remove all custom code related to this plugin and verify the native code works, it will help us determine it's something in your custom code. If it still doesn't work after that, then it's something in the software that's not working right for you.

    Thank you for your patience while we work through this issue.

    Best regards,

    James Morris

  • Luke

    Hello James, thanks for getting back to us. I commented out the custom code in functions.php & header3.php:


    I changed to a default Twenty Sixteen theme, added the native widget to the sidebar:

    And tested the search function:

    But it brought up nothing:

    Appreciate your help.

    Could this be because we are using a hidden IP address?
    I also want to be sure I set up the child theme correctly, because I have a feeling that could attribute to the problem.

    When I set up child themes all I really do is create a child theme folder (LMS-child), place a style.css file inside and add this code:

    /*
    Theme Name: LMS Child
    Theme URI: http://wedesignthemes.com/themes/lms/
    Author: the DesignThemes team
    Author URI: http://themeforest.net/user/designthemes
    Description: Child theme for the LMS theme powered by DesignThemes
    Template: lms
    Version: 3.1
    */

    @import url("../lms/style.css";

    I dont know why that would be a problem, but it could be??

    Let me know what next steps I need to take. . . thank you very much!
    Luke

  • James Morris

    Hello Luke,

    I hope you are well today. Thank you for your patience while we sort through this issue.

    With your site set to the default theme, and with you using the default code and widget for Global Site Search, would you please update your wp-config.php file as follows to enable WP_DEBUG.

    To enable WP_DEBUG, change the following line in your wp-config.php file:

    define('WP_DEBUG', false);

    To this:

    // Enable WP_DEBUG mode
    define( 'WP_DEBUG', true );
    
    // Enable Debug logging to the /wp-content/debug.log file
    define( 'WP_DEBUG_LOG', true );
    
    // Disable display of errors and warnings
    define( 'WP_DEBUG_DISPLAY', false );
    @ini_set( 'display_errors', 0 );

    Then, try to perform a few searches. If there's a problem in the code, some warning or error should be generated.

    Once you have done that, please reply back with any entries that are present in wp-content/debug.log.

    I look forward to seeing the results of your tests.

    Best regards,

    James Morris

  • Luke

    Morning James, I ran a couple of searches with the debug on and here is the log:

    [21-Oct-2016 14:42:18 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:42:18 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:42:34 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:42:34 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:42:55 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:42:55 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:43:07 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:43:07 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:43:17 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:43:17 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:43:18 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:43:18 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:43:48 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:43:48 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:44:02 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:44:02 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:44:31 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:44:31 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:45:34 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:45:35 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:46:59 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:46:59 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:47:04 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:47:04 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:47:22 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:47:22 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:47:27 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:47:27 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:49:32 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:49:32 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:50:30 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:50:30 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:51:46 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:51:47 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:52:29 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:52:29 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99
    [21-Oct-2016 14:52:55 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 27
    [21-Oct-2016 14:52:55 UTC] PHP Notice: Undefined index: disable-theme-default-courses in /srv/www/www.tutoringclub.com/wp-content/plugins/designthemes-core-features/custom-post-types/register-post-types.php on line 99

    I deactivated, deleted the re-uploaded the Global Search plugin. I also deleted the zip-code-post-type.php and re-uploaded it.

    Your guess is as good as mine
    Thanks for your help and patience with this. Whatever you need, I can get it done for you.
    -Luke

  • Luke

    Thank you James.

    I hope you were able to test it on our actual site/Wordpress install, because otherwise you would not be able to accurately simulate our issues (in regards to our dedicated hidden IP address, theme and associated plugins). Did you have a chance to login and test on our backend?

    Appreciate you sending this to the SLS team, hoping they will address this sooner than later, as the site is supposed to go live Monday October 31, 2016 (Halloween!!!!).

    Just wanted you to be totally filled in on the issue. Anything I can do to help, please let me know.
    Thanks again,
    Luke

  • James Morris

    Hello Luke,

    I hope you are well today.

    Yes, I had logged into your site but was unable to come to a resolution. Hence why I've flagged this to SLS. There's something going on programmatically that our Devs would be better suited to resolve. Unfortunately, I cannot give you an ETA on when this will be resolved, but I will continue to check in with our Devs so this can be resolved as soon as possible.

    Best regards,

    James Morris

  • Jude

    Hey Luke

    Hope all is well and sorry about the extreme delay here on this thread ! We were a having a hectic week and this some hoe slipped through the gaps.

    I remember helping James test this for you earlier and unfortunately Im not able to reproduce this either. I tried taking a look at your site to see if some JS could possibly trigger this ( no data returned etc ) however looks like your site is down / offline at the moment.

    Can you take a look and confirm if everything is ok please ?

    Cheers
    Jude

  • Luke

    Hi Jude! Thanks for getting back to us. I believe we are trying a different solution. . . WP Store Locator.

    The other solution was just too much trouble and I believe this Store Locator will function just the same and give us what we want.

    Let me know if you have any issues with this plugin route (Multisite/ext).

    Thanks again for getting back to us, I know how things can get busy sometimes
    Luke