I have a Wordpress page /users and it displays a list of all users created. Each user has a link to its profile page. What I need to do is create that page. I want it to go like this /users/{user_id}-{first_name}-{last_name}, for example - /users/1-john-doe. I have a template for /users and also for profile pages. Question - how do I properly make a page with that profile template so that it would have the url described above? The page does not need to select the user automatically, it needs to pass the user slug so I can read it in that page and query for that user (as a variable or something).
Thanks.
What you are looking for is the WordPress Rewrite API.
This allows you to define a new "endpoint" for your URL's, and allows you to pick up the variable from the URL via built-in WordPress functionality.
A great article on it can be found here: Custom Endpoints
Related
When creating standard pages we can use single or archive page templates or simply create our own page template creating a new page with the slug for example: photography and actual page: page-photography.php so we can write unique content to each page if we need to.
How can we do the same with custom post types?
So, I have a custom post type called services how can I create custom unique pages for each of my services?
I know I can write the content directly to each service page and pull it from there but this is not what I want. I would like to have full control over each service page.
Can anyone share the proper solution how to handle this, please?
I think, you can create a file with name single-{post-type}-{slug}.php
see more here, Single Post Template Hierarchy
So this is the my issue:
I have an 'huge' (more than 1000 pages) non wp website that i've ported to wordpress.
It's impossible to match the url's from the old website to the new
website because page titles and general information architecture
have changed
So in a custom post type that will hold the 'Listings' (listings_cpt) i've stored a custom field named old_website_url.
My goal was to intercept 404 requests with the template_redirect hook because from what i've read it looks like appropriate to intercept a 404 before the template is loaded and an actual header is sent.
So hypothetically if someone tries to see a page that doesn't exist but its url is stored in old_website_url from the listings_cpt posts i could redirect him to the post permalink that holds this value.
I've did a lot of trial/error approaches with no success.
Can someone point me in the right direction??
Is there a better way to accomplish this?
Thanks in advance
Well your approach should work. Here is what you need to do:
Create a custom 404 page that reads all posts
For each post read its old_website_url custom field
If the old_website_url custom field of a post matches the current url, the user is redirected to the url of the post.
Have a look at the WordPress documentation
I'm trying to make a custom page on a Wordpress site.
It is more or less linked to the Wordpress itself. The code is custom but I have used links to it from Wordpress Dashboard and normal pages.
The point is that now my boss wants to create a page like example.com/me/name and that should SELECT some data about the person.
Example: site.com/me/johnx
This should run something like SELECT FROM DB WHERE first_name LIKE 'john' AND last_name LIKE '%x' let's say.
How can I create my folder / file / function "me" so that when I type "/name" I can do an explode under it and use the last parameter to show the page?
Thank you!
Edit: I know about GET method.
As in example.com/me?name=johnx
But I want to know how to do it with simple slashes "/".
I think you should add a rewrite rule, which is a function called to tell Wordpress how to handle the URL's. You can find further info here.
add_rewrite_rule() allows you to specify additional rewrite rules for WordPress. It is most commonly used in conjunction with add_rewrite_tag() (which allows WordPress to recognize custom post/get variables).
So I built a site (In the wrong way which I can see now).
Users can post ads, they are not stored as a post, I just store the information in a table in the database.
I use a page template with parameters passed in - For example www.site/ad/?id=1&cid=2
id = id from database
cid = category id from database
I then use a wordpress page, pull params from url and load all information from DB relating to the id and category id.
In the wordpress admin there is a page set - the page uses an ad detail template for all urls that are www.site/ad/?
What I want to do now is put the ad title in the url so www.site/ad/adtitle/?id=1&cid=2
The issues with this is the page will not load as the permalink now does not correspond
perma link is www.site/ad/?
so cannot use www.site/ad/adtitle/? and still load the page with template.
I guess the question is can I make so that the page will load the url with the ad title in
I try to set permalinks to allow custom structure but no luck
Apologies about title didn't know what to call this
Fixed it with pods, which will allow you to use a page referencing a part of a url
http://blog.stefanxo.com/2014/02/how-to-create-a-pods-page/
Thanks
I want to build a multi user website where my users register and their account is created.
After sign up the user gets a specific url to build his website. Like. Mysite.com/user1
Now the user can login to the control panel and publish his data. Eg he has created a faq page.
His faq page should be available like
Mysite.com/user1/faq
I've done everything but this faq page building does not work at all.
I check the user for existence in the DB and route to his page in the routes.php file
:any = home/loader/$1
And in loader.php I fetch the details and display his welcome page, for the faq page, I have created a function in the loader.php controller as
Faq()
And built a custom view for it but now when I try to access the page it only loads the welcome page.
I tried all methods but it does not work.
I suggest you have a look at the Tutplus
http://code.tutsplus.com/tutorials/basecamp-style-subdomains-with-codeigniter
It explains how to work with wildcard routing in codeigniter