I'm trying to receive all portfolio entries from the database. I want to list this and also link the WordPress path to it. This is the SQL query:
SELECT id, post_title, post_name FROM 1bncopo2_posts WHERE post_type='portfolio';
post_title could be the following:
Mercedes-Benz AMG C63
Mercedes-Benz S500
BMW 650i XDrive
and now post_name for the first entry of the above list is mercedes-benz-amg-c63. However, I found that in my database table, multiple portfolio vehicles (even vehicles by BMW, etc.) have post_name set to mercedes-benz-amg-c63. My idea was to generate the URL to the portfolio item using post_name as an appendix to the wordpress path. TO BE CLEAR: This is going to be a seperate application reading from the WordPress installation's database and trying to make up the corresponding links to the portfolio items.
Now that post_name is not UNIQUE or something I could use, I have two questions:
Why would the WP database allow for duplicated post_names?
How can I get the post (portfolio)'s URL, if not by post_name?
It is impossible to repeat the link, if you see the link from the beginning you will find it different.
If this post (mercedes-benz-amg-c63) for custom post type called (portfolio) you see URL like:
www.domain.com/portfolio/mercedes-benz-amg-c63
But if its post type (post) you see URL like:
www.domain.com/mercedes-benz-amg-c63
Then as you see the URL not duplicated
Related
I've created a demo website where I want every post to have the same content. I've created 50 posts through a random post generator plugin. I have edited one post's content. Now is there a way to copy the content and paste to all 49 other posts?
E.g. I used this query to duplicate the excerpt.
$wpdb->query( "UPDATE wp_posts SET post_excerpt='This is an excerpt for the post' " );
Looking for a similar query. Please guide.
I have implemented normal search functionality in simple pages using php and MySQL where I get result rows by mysqli_fetch_array. There I could have any numbers of variable with AND or OR relationship and it will retrieve results from the db.
Now I am trying to do this in WordPress.
I have seen solutions where one uses WP_query to search by term names. How do I achieve this AND and OR variables in my search query.
For example, my query is like select all post title where term name like 'search keyword' AND term slug like 'hi'.
I have created a view terms_and_posts table from merging terms and posts tables using taxonomy relationship, with columns custom term name, custom term slug, post title, post content, post status, and post type.
Do I need a merged table or it can be achieved by modifying WP_Query?
I do not want to resort to using plugins as I am very new to WordPress, and I prefer not to use plugins as long as I can help it.
I am new to MySQL and PHP. I am having issues wrapping my mind around how to accomplish something. I am building a site that has basically a forum style post page. Users enter text into a textarea which then posts that text along with a timestamp and $_SESSION['Username'] into a MySQL table titled "campaigns." So the table has postEntry, postName and postDate rows currently.
On this same page that I have the form, I then display the entire contents of the campaigns table into a div. So it can show each post in descending order.
This has been working great for me, but I am now trying to look at the bigger picture and am thinking this is not a good way to do what I need. I basically need the ability to have an endless amount of "campaigns" each with their own set of posts. Then give the user the ability to select which campaign they want to view and show corresponding posts for that campaign in the div.
So the real question is: Is there a way to do this with just one table. Or would each campaign need it's own table in the database?
Add a campaign_id to the POST table and viola!
edit: more info:
you need one table for the campaign like so:
Campaign
-------------
campaign_id
name
then you need another one for all the posts
post
-------------
post_id
campaign_id
post_time
name
this way, each post is associated to a specific named campaign.
I'm looking for a solution to list and browse categories and subcategories and their records (classified ads), when you store category levels in separate tables. In the past I have worked with the adjacency model but I have to stick to this database setup now, and it is new to me. I'm using php and mysql.
The site is a classified ad site structured the common way: it has the main category list on its homepage, when you click one of the category links then only its subcategories are listed and the ads that belong to this category, and so on, at every level.
I'm a bit confused in the following areas:
How do you construct
the category links when browsing
categories in order for the script to know which table it should select categories from if I consider the below
mysql structure? Do I need separate
parameters at every category level I access
like e.g: "mysite.com/?cat2=4" when
accessing category "4" in the cat2
table and "mysite.com/?cat3=9" when
accessing category "9" in cat3 table
in order to identify category
levels? If separate parameter not
needed, then how can php and mysql
tell what table you have to select
the categories from?
And most
importantly in this case, what is
the best way to construct SEO
friendly links? And how will mysql know
which table to select categories
from? I would like to use the most
simplest solution that is possible
like:
mysite.com/electronics/television/sony.
As far as I know, I have to include
at least the cat_id
somewhere in the link... where do I put it? and do I have to include the number of level as well? To
complicate it more the category
names are in foreign language with
accented characters (though I
created a function that changes
accented characters into latin ones
on the fly when generating category
links) so I think it is best to
select them by their ids.
How is a sample mysql select looks
like that selects the child
categories of a certain category?
How can I construct breadcrumb
navigation?
MYSQL STRUCTURE:
Table "cat1" (main category):
cat1_id | cat1_name
Table "cat2" (subcategory):
cat2_id | cat1_id | cat2_name
Table "cat3" (subsubcategory):
cat3_id | cat2_id | cat3_name
Table "ads":
ad_id | cat1_id | cat2_id | cat3_id | ad_title | ad_description
Thanks and sorry for the long post.
My favourite pattern for category (and tag) URLs:
http://mysite.com/articles/brains+zombies+legs+frogs
The + symbol is nice for tags, and friendly to spiders (and SEO). Using the text of the categories is important for both spiders and humans as it's meaningful.
As for the SQL, I suggest 2 tables for anything with categories or tags:
Categories (id, name, description)
CategoryRelationships (catID, thingID)
For any given thing, you join Categories to Things via CategoryRelationships. For example:
SELECT * FROM Things t
JOIN CategoryRelationships ON thingID = t.ID
JOIN Categories c ON catID = c.CatID
The result will be a list of Things and their categories, where you have only one definition of each category, and a bunch of links to the categories via the Relationship table.
As for breadcrumbs, they're a slightly different problem. Breadcrumbs either:
Provide navigation through your site hierarchy, or
Help the user retrace their steps
Depending on the type of breadcrumb you're aiming at, you take a different approach. For a simple site hierarchy set of breadcrumbs, you can simply parse the URL and foreach over the set of segments:
http://mysite.com/people/zombies/brains/brains
Parsing the URI would result in:
people, zombies, brains, brains
For which you would generate links to each segment.
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.