i still , don't understand , how wordpress can understand what is this url refer to :
www.mysite.com/about-me/
they are using no identifier
if they using slug functions so how they can retain story information or in other word , how they change back the slugged title to select from database
It processes the "pretty" URL and queries the database with that data. Of course slugs are checked to be unique on creation. Details are in the function url_to_postid() in the file wp-includes/rewrite.php.
If you want to directly obtain the id from the slug you can query the database:
SELECT ID
FROM wp_posts
WHERE post_name = '$slug'
you might need to check wp_posts which is the default name, but it depends on the installation.
This is just a guess:
My guess is that they store the titles in a database, and make sure every title is unique. That way, they can do a look-up by title and know which item is coupled to that.
Related
I have a website with coupons and a large database. In wp_postmeta most of my posts have a store_id, because I use the plugin Yoast SEO and it sets the meta_key and the meta_value. Not all of my coupons have a store_id in the wp_postmeta, like the older coupons or some of them who was copied from the old ones, or who came automatically through API.
If I update every coupon and re-click the store part, the post gets the store_id written in the table wp_postmeta. But I have more than 50 000 coupons... I need the store_id set for every coupon I have, for other tasks I need to do.
Is there an easier way how to do this, without manually updating every coupon?
First, please make a backup.
If I understand correctly, yoiu need to change every row in the wp_postmeta table to set the store_id to the same value. If I've misunderstood in some way, that is, if you need to set a different value for some rows or if you don't want to over-write existing data, you should stop reading here. I don't know anything about Yoast SEO and only know as much as I've perceived from your post here.
But changing a single column for all rows is easy. You need an SQL statement something like this:
UPDATE `wp_postmeta` SET `store_id`=1
That will change the store_id of every row in wp_postmeta to 1.
Since you've tagged phpMyAdmin, presumably you're using that as your interface. Just click the SQL tab once you're in your WordPress database to enter the text of the query directly there.
I've been thinking about how does people make a special link like
www.domain.com/this-is-a-link
then i checked how to make a slug URL and it was good, But i was wondering, Do i make a special column for SLUG URL inside the database and call the entire row using the SLUG instead of the id? Is that how all people do it? Or is there a better way?
[id title content slug]
[1 TheTitle LoremIpus the-title]
$query = "SELECT * FROM posts WHERE slug = $slug";
What you are looking for is URL rewriting. Please search on that topic. You will find articles like These, which has information about the URL rewriting!
I'm trying to figure out to get a complete clean url for my blog. Right now I have a decent url that looks like this:
http://example.com/post/44/post-name
Here "44" is the Post ID which I use to get the correct post from the database.
But I have seen wordpress blog having url's like this:
http://example.com/post-name
How can this be achieved? as I need the post ID / $_GET['id'] to be able to get the post.
You don't necessarily need the id to retrieve the Post. You only need an indexed attribute with unique values.
To achieve this, your Post model needs to have a "slug" attribute. That slug attribute can be based on any other attribute or combination of attributes you choose, but it's usually based on a "name" or "title" attribute.
So to make all this work, when you create a new Post, you need to create a slug from the name/title and store that in the DB, along with the other Post model data. In your controller action you will then retrieve the /slug from the URL and query the db Post data for a Post with the same slug.
You'll also need to figure out to handle duplicate slugs as they need to be unique. Perhaps something like this would work: /slug-2
Make a database table mapping slugs to IDs, then lookup the ID from the slug in the URL.
When a blog is created,
INSERT INTO slugs_postids (slug, id) VALUES (?, ?);
Then when you do a lookup,
SELECT id FROM slugs_postids WHERE slug = ?;
I have a wordpress blog with 2000 posts. Name of each post is a person's name. But the first name and last name are separated by a '-', I want to automate the process of removal of these '-' from the post names.
Example -
Present name of a post: Isaac-Newton
Desired name : Isaac Newton
Is there any script, or code to do it, as it will be a tedious job, If I have to manually edit the names of all the posts. Any help, suggestions what might work?
You could open the WP database in PhpMyadmin and run something like the following:
update wp_posts set post_title = replace(post_title, "-", " ") WHERE post_title LIKE '%-%';
Obviously backup the database first, to ensure you don't completely mess it up.
I am using the CodeIgniter framework and am having trouble figuring out how to get my urls to display the category name but still have my queries reference the category id.
I have a controller set up called jobs. The structure of the url is "example.com/jobs/listings/category_id" example: "example.com/jobs/listings/3" where 3 would be the category id for "software".
I'd rather the url say "example.com/jobs/listings/category_name" example: "example.com/jobs/listings/software".
The problem I'm running into is that the "jobs" table holds stores the category_id that the job belongs to and not the category_name. I have a separate table that holds just the category id's and their names. I'm not sure how to A.) Write my query and B.) Make an SEO friendly url structure.
My current query looks something like "SELECT * FROM jobs WHERE cat_id = 3;
Also, I'm not sure if I should be using mod_rewrite in an .htaccess file or if I should be using the routes.php file in CodeIgniter.
Any help would be greatly appreciated!
-Thanks
Just join to your other table.
SELECT * FROM jobs JOIN categories ON jobs.cat_id = categories.id WHERE categories.name = ?;
Make sure to put a unique key on the category name, if you don't have one already.
mod_rewrite is a poor solution to app routing and wouldn't help much here anyway. Stick to whatever your framework provides.
Have a look here http://codeigniter.com/user_guide/helpers/url_helper.html at URL_title()
Convert you category name using the url_title() function making sure you have no duplicates.
When a url is called Look up your category from your model using a simple where statement
Eg
$this->db->from('categories');
$this->db->where('name', $url);
Etc...
Use this to load your page titles etc then use the categoryid returned to do the look up on your jobs table.