wordpress - how let users add location on a map? - wordpress

I'm using Wordpress to build my website, i want to add a form that will have: name, description, image and location on a map. that is letting the users add their own marker on a map.
and by pressing 'submit' the whole data (name, description, image, longitude, latitude) would be saved to a database.
how can i do that? which plugins should i use?

You could use Google Placemarks and give them access to the creation of the 'Placemarks' custom post type that plugin utilises. You might have to hack the featured image..
Alternatively, you're looking at full custom post type creation and google maps API integration, a custom loop that utilises of the featured image.

Plugin that comes closest to what you need is what SMacFadyen suggested - BGMP. But if you want to do that yourself you would need to look into this:
Google Maps JavaScript API
WordPress Custom Post Types
WordPress Meta Boxes
For the first one there is lots of tutorials on how to display map and InfoWindows so you shouldn't have much problem with that. For Custom Post Types there is an awesome generator which should do 99% of your work. For Meta Boxes you can go several ways:
plugin - easiest but you would depend on a plugin which I don't like very much
from scratch - tutorial - which is a lot better than plugin but requires a lot of work
one of the meta box libraries - this is the way I usually go - I'm developing my own but it's not ready yet so in the mean time I would recommend My-Meta-Box or Reusable Custom WordPress Meta Boxes

Several times, when searching how to make this work, I stumbled upon this thread. Every time, I wasn't really happy with the way existing plugins deal with this. So, I now put this together myself.
Here's an overview of my solution.
Use the plugin Custom Post Type UI to create a custom post type for the markers on the map.
Use the plugin Advanced Custom Fields to add a field to this custom post type which represents the location. The field type is of type 'Google Map'.
Copy the standard Google Maps API clustering example to the appropriate theme file in your theme.
For showing your markers, generate the list of locations by, in your theme file, requesting the posts of your newly created custom post type.
For each marker/location, pick up the 'Google Map' field and abstract the latitude and longitude.
For each marker/location, construct the appropriate array element for the array with all locations, with, at least, the latitude and the longitude, and probably also the contents of an infowindow.
This should give you a map with all locations plotted out.
To allow users to add locations:
Add a listener to your map that listens for clicks and returns the location clicked. Perhaps this listener is only running after the user has expressed his intent to add a location to the map.
When the user has clicked, open a form, for example in a modal. The form should contain hidden fields with the latitude and longitude and could, for example, also contain a static image of the relevant location. Other form fields would be the fields you need for your purpose.
Submit the form using AJAX. Refer, for example, to this tutorial. In your theme's functions.php, you can then validate the submission and add the new submission to your Wordpress database, matching your new custom post type.
Depending on how you store your new location, on your next map reload, the new location will be included. (Or you perhaps need to authorise the new location, first.)
You can also reload all locations through AJAX.

Profile Builder allows you to do just that. Create a front-end register form including the required custom fields and a map field for users to pin or enter their location.
Then using the built-in User Listing (Member Directory) module, you can display a map of all users locations.

Related

How can I fetch the post slugs of all languages?

I have a react project which fetches data on wordpress via api calls (plugins installed: ACF and WPML).
I have the Event CPT and viewing the page localhost: 3000 / events / first-event, I retrieve the information via the slug.
If on this page I wanted to retrieve the same event in another language, I could add the country code in the url and make a redirect.
It is possible that the same event has different slugs based on the language and the feature does not work.
Do you have any ideas on how to make this feature?
Thank you guys!
I have temporarily modified the pathname.
<a href={window.location.pathname.replace('/','/en/')}>EN</a>
I have found the solution.
I used the icl_get_languages() function to fetch the languages, icl_object_id() to retrieve the post id of a language, get_post to retrieve all fields and update_post_meta to add a custom field to the post.
Hey I have the same setting but not with React.
If you are using the API without any modifications in the class and given that the title between language is the same try the following:
/wp-json/wp/v2/posts/?post-slug=second+post&lang=fr
and page slug
/wp-json/wp/v2/pages/?page-slug=second+post&lang=fr
However, you need to modify the API response if you want your ACF fields to be there (or use a plugin).
Also mind that post ID between translations is different. Ensure to include the lang as argument in the modification of the WP_REST_Controller. https://developer.wordpress.org/reference/classes/wp_rest_controller/get_collection_params/
Let me know if that helps.

Add a new section to the wp-admin edit post page

One of my post types is called Events and on here I have typical things like a post title, body, event date, etc.
In the site's code (on a custom template), I am programmatically adding meta to events when a user signs up (custom array of values).
The problem is that an admin can't see this data.
I wanted to know how I could add a custom section or template so when an admin inside wp-admin goes to any given event, and edits this single post/event, they can see the metadata associated.
I want to just add a new field section somewhere, called "Registrations", and then I'd programmatically access the meta and format it how I want, put some HTML/CSS in there, etc.
If anyone could point me in the right direction I would appreciate it.
Thanks!

How to create a user input form with WordPress?

I'm completely new to the whole WordPress scene so I kind of don't know the "WordPress way" of doing the desired task:
Create a form where a user would fill in some details (such as name, surname, upload a video or post a youtube iframe link)
Submit it, once it's done - an admin must verify that everything has been filled out correctly and after that the video can be seen on the website.
Should I write a plugin of some sort that would do that or how does it happen?
Thank you.
The Gravity Forms plugin allows you to do exactly what you're looking to do. With it, you can set up a form that creates a post and sets it to be 'Pending Review' in WordPress. This tutorial contains everything you need to know about what you'll need to do.
If you want to create a Custom Post Type (ie. 'User Page') to better separate user submissions, you'll need to employ this special add-on (as mentioned in the tutorial above).

How to use custom fields globally in Wordpress?

I'm trying to use the value of one custom field on multiple pages and posts. I'm a newbie to PHP and custom fields so what I'm trying to accomplish could possible be done using a different method.
I have a WPMU setup with all new sites created from a default blog that includes multiple custom post type templates. When users create a new site they are redirected to their site admin dashboard.
Here comes my challenge, I want users to be able to enter information into form fields contained in metabox(es) on their admin dashboard (not post editor) that will be used on the various custom post type templates. For example, a user will need to enter their company name, address, logo, etc.
Depending on the temple, the information entered into the form fields will be used on the frontend of the site. For example, the company logo will be display where the custom field or shortcode is placed on the post template.
I'm having issues using custom fields for this because each custom field is specific to each post. In addition, I'm having issues rendering a form on the admin dashboard for this.
I'm also thinking that custom fields may not be the best way to accomplish my objective because they are usually post specific. I'm really asking for a variable that will be used globally and is static unless the user updates the form.
I'd appreciate any assistance on this.
The options API is what you will need for this:
http://codex.wordpress.org/Options_API
There's also some plugins and frameworks you can use to help such as:
https://wordpress.org/plugins/options-framework/
https://wordpress.org/plugins/redux-framework/

Show data on a specified template in wordpress

I am using one plugin known as Wp store Locator which is not based on custom post type.So that plugin gives one list of store as output and it has in built template for it.I have modified that plugin in a such way that on click of More Details it should take me to detail page of that particular clicked store.
I have built link like this localhost/wordpress/?wpsl-id=3.
So my question is that how can I show only on particular store? I have built one template in that plugin but I don't have any idea how can I use that.
Any help from Wp Store Locator user would be highly appericiated.

Resources