As mentioned, i need to list all users (Already haves this) – And then each company needs to have a link to their own profile page (frontend, NOT backend), which should contain information about the “user/company”…
I thought about using the “author.php”, however it’s not authors I need, but actual registered users(companies) in the system…
I guess, from the listview i would have a link like: https://mydomain.com/companies?id=XXXX and then create a custom page that gets the id and make a query to the database after this user…. However, then I dont get the “pretty” URL structure like so: https://mydomain.com/companies/companyname
Really hope someone can help…
]]>As for displaying user/company data through a pretty permalink, again, create a custom page template. Use the Rewrite API to convert the pretty permalink into URL parameters that the page code can get through $_GET.
]]>I my list, then I would create a link like: Link to company profile page – However, this still leaves me with a rather “ugly” link ?
When a visitor click the link, then they would be redrected to https://mydomain.com/companies/company?userid=XXX – And then you would use the RewriteAPI for getting a pretty URL like: https://mydomain.com?companies/company/companyname ?? But how will you replace ?userid=XXX with the companyname?
So when linking to the profilepage from the list would I then create a link like so: Link to profilepage
Then how would I fetch the ID of the company on the page template, as I cant get the id from the querystring? ARGH, im confused ?? ??
Im pretty new to the WordPress API, and never touched rewrited rules before, so im completely lost on how my setup should/would be for achieving what I want…
Could you provide a small example perhaps? That would make me a really happy camper ??
]]>all the above can be done using plugin for membership like members
]]>Let’s get the user/company information first. You need a custom page template. The only requirements are that it resides in the theme folder and has a comment header that has a line that begins “Template Name: ” followed by a name.
On the template build a standard HTML form. The form method should be POST and the action attribute an empty value so the form submits to this same page. You can get the current user’s WP_User object with wp_get_current_user(). This object will contain some basic information about the user. Some of it can be presented as read-only information, like the login name, since no one can change it. Other fields are editable. Use the properties from this object to pre-populate form field values. Include hidden fields for security measures like verifying the user ID and a nonce value.
You can add in security measures later, but the form should not be presented to regular users until security is in place. For now, a line that verifies the current user is you is enough. Just call wp_die() if it’s anyone else.
You will be storing other values in user meta, or they already exist there. Get these values as well to pre-populate fields when they are available. Most of the page is displayed the same way regardless of whether it’s an initial GET request or after a POST submit. The one important distinction is POST request code needs to save the form data. This save the data section is managed as an if ('POST' == $_SERVER['REQUEST_METHOD'])
conditional. Within this block is all code to take data from the submitted form (in the array $_POST) and validate and sanitize it prior to saving it in the DB.
You’ll eventually need code to verify the user ID in $_POST matches the current user and that the passed nonce value is correct. If some users should not be able to edit their profile, then there needs to be a capability/role check as well.
To start with, maybe your form only has a few fields. If you can successfully present existing data in the few fields and save updated data upon submit, then it’s time to celebrate! Now it’s just a matter of adding in more fields and doing security checks.
Presenting a selected company profile to visitors is not that different than the profile form, except there are no form fields or POST requests. But you still get the saved data from the DB and output it in an organized manner. After the profile form, this page should be easy.
Which leaves us with the company listing page. It’s going to be much like a post archive template, except the query will be for users instead of posts.
Once you get these three pages working in a very rudimentary way, it’s just a matter of improving upon the basics, one step at a time. Don’t sweat all the little details involved, solutions exist. Just focus on the immediate goal you are dealing with, forget about the rest. Eventually, everything will come together ??
]]>