MySQL query to fetch this data in Wordpress - mysql

I'm not very good with MySQL queries, I'm looking to fetch the columns from multiple data using MySQL query. Considering DB name is "db_name" and prefix is like "wp_",
post_name
post_title
post_content
featured image url
categories
tag
Can I fetch this stuff in a single query or I have to use multiple queries? The categories and tags are the ones that would be associated with a given post. Any help would be appreciated.
Thanks!

Related

Mysql Query Help to compare multiple urls

I have a db with 14k links, im trying to find each url that is in the db twice or more.
Using this query below I'am able to strip them down to simple url's.
SELECT SUBSTRING_INDEX(url,'/',3) FROM Links WHERE url REGEXP '^[^:]+://';
I'm looking for help in now taking the results and counting them to present a list of all the domains that have 2 or more entries in my DB:
Once you strip down all the URLs to their simple form you can use the following query to find the no. of counts of the URLs appearing in the db.
SELECT *
FROM `Links`
GROUP BY url(`url`)
HAVING COUNT(*) > 1

Batch add tags to posts via phpmyadmin - wordpress

How would I go about batch assigning tags to posts via phpmyadmin? I have a custom table in my database that contains the postID and one column with a comma separated list of keywords for each post/record. I want to use the keyword column as values for my tags for each post.
Is there any way for me to get those tags over to the wp_term_relationships table using an sql query?
Right now I already have each post assigned to one category (and some posts assigned to two categories)...if that makes any difference....I am dealing with almost 200,000 posts.
Thanks for the help!!
I thought I could do this with sql queries but that is just over my head..so I did some extensive searching for plugins (free plugins that is...).
I came up with this, which is working....
Installed the 'WP Post Corrector' plugin, it is old and not updated anymore but it is working with my 3.5.1 wordpress. I have a massive csv file with 2 columns (ID -> which is the same as my wp post ID, and post_tag -> which is a list of comma separated tags). I split the file up into smaller chuncks so php or the server wouldn't crap out (http://sourceforge.net/projects/splitcsv/) - I made each file have 5000 records.
Yes, it took me about an hour to upload about 40 files, but now it is done.

MySQL query - single product with multiple reviews

Thank you in advance for any help you may be able to offer!
I'm working with an a bit of an odd database where products are related via tags and are not hierarchical.
I'm trying to select a single product using a SKU number from a table and join it with a table of product reviews like so:
SELECT ims.master_sku, ims.title, ims.price,
ims.description, ir.mvp_number, ir.title,
ir.review, ir.rating, ir.created_on
FROM default_inventory_master_skus AS ims
JOIN default_inventory_reviews AS ir
WHERE ims.master_sku = '22284319'
GROUP BY ir.review;
This gives me around 150 rows - which are all the same product but contain different reviews. My question is how can I return just the one product (as a single row) and somehow convert the reviews into columns associated with that one product?
Again - thank you for your time and help.
Rich
You can do that, although it's not "relational".
Looks like someone wants this data in Excel ;).
With MySQL, you will need to generate an SQL statement and execute it. Either within MySQL (in a procedure) or outside (e.g., in PHP). Query first for the pivot column names, put together the statement, then execute it.
An idea of the implementation is here:
http://www.artfulsoftware.com/infotree/queries.php#78

Search page engine PHP with MYSQL database?

I'm going to generalize this question so that other people can use the answers.
Let's say I have a website driven by a MYSQL database.
Database contains 5 tables:events,news,books,articles,tips.
Every table has among others 2 fields Title and Details in which I want to search
On every page of the site I have a search form (text field and button).
After I type a word or phrase I want to be redirected to a page called search where I should see the results as a list with links from the entire database.
e.g.
Book X (link on it to the book found in the database)
Event Y
Article Z
HELP: The tables are INNODB ENGINE so full text search didn't work also I'm having trouble in building a SELECT statement for searching multiple fields from multiple tables with LIKE. I've succeded with one table but with multiple tables and multiple fields I'm getting error or no data or duplicated data in some cases. Some help with this Select statement please.
Question: How do I build a search engine for all the tables in my MYSQL DB? Some SQL injection or other hacking prevention advice would be appreciated also.
My Approach to the situation is create a view based on all the tables with similar columns ( columns which we need to search only) and one more alias column with their table names/ entity name (Books, event etc)
It should look like this
EntityName Title Details
Books xxxx xxxxx
...............................
I am not explaining how to create views with union (dont use Union All if not expecting duplicates).
The next stop would be search using like statements
select * from vwSearchData where Title like '%keyword' or details like '%keyword'
Next step is to display the data along with their entity names.
Ofcourse, you need to get the keyword by filtering with html entities from the search form.
You can use UNION:
(SELECT * FROM events WHERE title LIKE '$key' OR details LIKE '$key')
UNION
(SELECT * FROM news WHERE title LIKE '$key' OR details LIKE '$key')
and so on.

WordPressMU - get blog list, alphabetically sorted by blogname

In WordPress MU, I've tried writing my own query for this but can't seem to get all of the joins I really need. The result set I'm looking for would be something like:
blog_id
blog name
blog path
owner first name
owner last name
and return it all alphabetically, by blog name. The trouble I'm having is that the first and last name of the blog owner are in wp_usermeta, the blog id and path are in wp_blogs, and the blog name is in wp_[blog id here]_options, with wp_usermeta requiring the user ID from wp_users.
Is it possible to join all of this in one query?
There is not a way to combine all of the information into one result set because of the way WPMU handles the database table names.
The best solution I have come up with is some PHP logic that gets the blogs from the wp_blogs table, uses the IDs there to gather information from the wp_X_options tables, and then builds up the information I need. It's the same reason there is no good way to get a list of all the posts across all of the blogs with just a query. You need backend logic to build the query based on the blogs in wp_blogs.