Allow user to select location and then set cookie for location in WordPress

I am needing to allow a user to select a location from a dropdown on the front-end, that then sets a session cookie for that chosen location... any help here? Ok so this is the outlined task: Location selector: 1st step is to simply have the location option slide down and then save the PHP cookie for later use I am getting the cookie to set ' add_filter( 'query_vars', 'addnew_query_vars', 10, 1 ); function addnew_query_vars($vars) { $vars[] = 'loc'; // …
Category: Web

Maps search box autocomplete with callback JS function?

I am struggling with using a callback for my Google Maps API. I am trying to have a Goolge Maps autocomplete search box and collect the Lat and Long for the searched location. I've found this answer that works really well, but sometimes the search box won't load the location suggestions. I've found that this might be caused by the google.maps.event.addDomListener(window, 'load', initialize); that I use. Instead I've found that I need to use a callback in my script. I …
Category: Web

Post queries by latitude and longitude

I am struggling with getting post queries by coordinates. I have meta fields map_lat and map_lng for almost all post types. I am trying to return posts from one custom post type ("beaches" in this example): function get_nearby_locations($lat, $long, $distance){ global $wpdb; $nearbyLocations = $wpdb->get_results( "SELECT DISTINCT map_lat.post_id, map_lat.meta_key, map_lat.meta_value as locLat, map_lng.meta_value as locLong, ((ACOS(SIN($lat * PI() / 180) * SIN(map_lat.meta_value * PI() / 180) + COS($lat * PI() / 180) * COS(map_lat.meta_value * PI() / 180) * COS(($long …
Category: Web

How to sort store location by specific category order in WP store locations

i want show if store has specific category then should be show in first and then order by distance add_filter( 'wpsl_sql', 'custom_sql' ); function custom_sql() { global $wpdb, $wpsl_settings,$wpsl; // Set a limit for the results and order them by distance. if ( isset( $_GET['autoload'] ) && $_GET['autoload'] ) { $limit = ''; if ( $wpsl_settings['autoload_limit'] ) { $limit = 'LIMIT %d'; } $sql_sort = 'ORDER BY distance ASC '. $limit; $sql_sort = 'ORDER BY field(ID, 9, 1, 4)'. $limit; …
Category: Web

Wordpress Query for CPT that only shows posts within radius of current user's geolocation

I have a CPT called medical_providers. Each medical provider has two ACF meta_fields (latitude and longitude). I want to write a wp_query to only show medical providers that are within a certain range (100 miles?) of the current user's IP address. Here is my query so far. It does not include anything related to geolocation. <?php $paged = ( get_query_var('paged') ) ? get_query_var('paged') : 1; global $wp_query; $original_query = $wp_query; $args = array( 'post_type' => 'medical_provider', 'posts_per_page' => 12, 'paged' …
Category: Web

Where does WordPress store plugin (enabled/disabled) status for multisite?

A recent update to one of the plugins I use broke my multisite blog and in the process of debugging it, all of the plugins got disabled. Now I have to try to figure out which plugins used to be enabled, but that's a big chore for various reasons. I've probably got at least one backup since the last time I toggled plugin, but I don't know where WordPress stores plugin state information for a multisite blog. I tried dumping …
Category: Web

Generate a radius search of custom post type locations

Alright so I've been searching for days and driving myself crazy looking for a solution. I want to create a search function that will allow the user to search for the companies locations that are closest to a location they enter. I already have a custom post type locations and I'm using the advanced custom fields plugin. With ACF I can get the longitude and latitude of a location. Here is the loop that I have so far. Right now …
Category: Web

Wordpress pagination not working with search page

In my search page, My query returns 11 pages with this search: ?q=2&s=chem But when I try to access another page other than the first, like ?q=2&s=chem&paged=2 for example, WordPress shows error not found. Note: If I leave empty s variable in URL, I have no problem. This is my WP_Query : $args = array( 'number' => $number, 'offset' => $paged ? ($paged - 1) * $number : 0, 's' => $_GET['s'], 'meta_query' => array( 'relation' => 'OR', [ 'key' …
Category: Web

multi-vender wooCommerce ability to separate products based on zip code

I have a multi-vendor WooCommerce equipment rental website where venders from multiple locations are able to offer their equipment for rent in their area. Currently I have all the products in the same product categories and subcategories. Is there a way to make a user choose their location first, and then all the products will be filtered out for them based on their location until they change their location preserving the directory structures? I know I can use MDTF to …
Category: Web

Add filter post_where and passing post_type argument

Following this tutorial, I want to search for posts within the radius where the post_type=profile add_filter('posts_where', 'location_posts_where', 10); $query = new WP_Query( array( 'post_type' => 'profile' ) ); remove_filter('posts_where', 'location_posts_where', 10); function location_posts_where( $where ) { global $wpdb; $latitude = filter_input( INPUT_GET, "latitude", FILTER_SANITIZE_STRING ); $longitude = filter_input( INPUT_GET, "longitude", FILTER_SANITIZE_STRING ); // Specify the co-ordinates that will form // the centre of our search //$latitude = '-27.922459'; //$longitude = '153.334793'; $radius = '125'; // (in miles) if (is_search() && …
Category: Web

Optimizing a Proximity-based Store Location Search on a Shared Web Host?

I've got a project where I need to build a store locator for a client. I'm using a custom post type "restaurant-location" and I have written the code to geocode the addresses stored in postmeta using the Google Geocoding API (heres the link that geocodes the US White House in JSON and I've stored the latitude and longitude back to custom fields. I've written a get_posts_by_geo_distance() function that returns a list of posts in order of those which are closest …
Category: Web

How can I implement a location based (zip code) search in WordPress?

I am working on a local business directory site that will use custom post types for the business entries. One of the fields will be "Zip Code." How can I set up a location based search? I'd like visitors to be able to enter their zip code and choose a category and show all the businesses withing a certain radius, or all the businesses ordered by distance. I saw a couple plugins that claim to do this but they don't …
Category: Web

Location-Based Content

I am building a site that has pages that have a contact pod that has 11 different dropdowns in wp-admin via Advanced Custom Fields. Based on the user's IP, I want to display one of those 10 contacts (the 11th one is a default if location isn't given or it doesn't match one of the client's "regions"). The 10 regions are all based on parts of the United States, but don't match to states all the time (for example California …
Category: Web

Generating a radius search on postmeta-metavalue and adding a taxonomy to query

This is an old SQL statement found on here from way back in 2011, but its the closet to doing what I need I could find and work on. Although it does exactly what I need, displays properties within a given radius of currently displayed property, I need to add the taxonomy for the contract type in so it only shows properties, given radius, contract type. I've tried all sorts, but cant quite figure out how to join the table …
Category: Web

Searching post types

Is it possible to take a user input from a search form, use that to search a custom post type via the WP_Query class and then redirect the user to a page template to display the results? For example, Assume you have a search input that takes city, state or zip You then enter in California, next that input is then captured and the WP_Query is used to then search custom post type "Locations". It finds 4 locations matching, you …
Category: Web

Help with WordPress search

i am creating a directory using WP, and need to allow customers to be able to search by industry and sector, like here http://www.checkatrade.com/ I will be setting these up through two taxonomies: 1: Industry 2) Location Can anyone help me?
Category: Web

I have geocoded posts with latitude longitude - How to search by radius?

I have posts which are geocoded with latitude and longitude from Google. I basically can enter an address in a post custom field and the latitude and longitude are placed into two separate meta fields. I'd like to create a custom search letting visitors search their zip/postal code and find the nearest locations. I've found this plugin which does all that bundled in one with custom post types then a search page http://wordpress.org/extend/plugins/wp-find-your-nearest/ I was thinking to try and modify …
Category: Web

Dynamic User State & City selection

I need to implement a state-city selection for my users to choose from. Where they first choose their state and then there is a city drop down field that shows only the cities in that state. Currently, users have to type in the state and city for their account. This concerns me because they may not enter the correct names. I would like this in order to keep these values consistent and to make the site more user friendly. I …
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.