SQL (Structured Query Language) is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS).

learn more… | top users | synonyms (1)

1
vote
1answer
842 views

How to Mass Delete Images from Media Library

I need your help. I am trying to mass delete attachments from a custom post type ('book') using a sql query. I found this snippet on the wordpress form: Wordpress.org I tested it on my local ...
0
votes
0answers
42 views

How to get list of posts with specific tag in separate category

I have a custom search function in my functions.php. And I need to change it, so that it will search also by tags in a specific post category (with ID 6 for example). For example someone search ...
0
votes
1answer
49 views

Slow query when joining wp_posts with a lookup-table?

I'm developing a map-based website and need to get posts associated with a place. Each place has a post in wp_posts and the other associated posts (images of each place etc) is associated with the ...
0
votes
1answer
70 views

SQL - Remove All The Users and Create A New User With Admin Role Via PhpMyAdmin

It is very easy to remove all the users and add a new user with administrative role via wp admin panel. But the requirement is to achieve this through SQL. I can trunc wp_users and wp_usermeta table ...
2
votes
1answer
99 views

How to update records using $wpdb?

I am migrating non-wp database to Wordpress (for the first time in my life, and hopefully the last). As both new and old websites are multilingual, one of the tasks for me is to connect the articles ...
0
votes
0answers
111 views

WordPress it's cleaning a custom query_var to avoid sql injections?

I am using get_query_var function to get a custom query_var. This query_var will be used later in to query arguments to retrieve posts with: $the_query = new WP_Query( $args ); . My question is, ...
0
votes
1answer
29 views

Why this query is not showing any result on wordpresss home page?

I am learning wordpress database, And I have written this query for showing the data from the post table with id=2, but not showing anything. What is wrong with the following query? please help. ...
3
votes
3answers
2k views

WPDB Insert or if exists Update

I'm not crazy familiar with WPDB or SQL in general but I have a custom table for my project and I'm trying to assign some metadata to it. What I'd "like" to happen is if a row exists, update it and if ...
1
vote
2answers
103 views

Query that joins the postmeta table twice

I believe what I'm trying to do is too complex for the standard meta_query parameter in get_posts, so I'm trying to use a custom SQL query to do the following: I have a game custom post that has ...
0
votes
0answers
179 views

Would manually deleting the dumping data fix a “#1062 - Duplicate entry '1' for key 'PRIMARY'” phpMyAdmin error?

I'm new to PHP! I'm trying to import an SQL database file into myPhpAdmin for a WordPress I'm migrating, but I keep getting this error message: SQL query: `-- -- Dumping data for table ...
0
votes
1answer
77 views

phpMyAdmin displays error when importing database

I'm migrating a WordPress for a friend to a different server. I have already backed up all files and was given a copy of the database by the old server admin. The problem is that when I try and import ...
0
votes
1answer
83 views

Pre_Get_Posts order DESC not registering

I've created a filter function to filter a post type items by it's meta value _item_price. The problem is that it only works in Ascending Order and I'm not sure why. My pre_get_posts function looks ...
0
votes
1answer
51 views

Convert all dates in field to Unix time, except those already in Unix time

I have a meta field that is mixed with MM/dd/yy hh:mm dates and Unix timestamp dates. How do I convert all of the MM/dd/yy hh:mm dates in the db to Unix? I have only limited PHP and SQL knowledge so ...
0
votes
1answer
35 views

How to add data from wordpress tables to new database tables you have created

I'm just learning this database stuff and so I am a bit confused and was hoping someone could push me in the right direction. I have managed to create users in the wp_tables I have created in my ...
1
vote
1answer
36 views

How to find meta entries with their posts missing via SQL?

I'm looking to write an SQL query to do the following: Select all postmeta rows where the meta_value = a post id that does not exist. For example, postmeta meta_value may equal 235. Usually this ...
0
votes
1answer
110 views

How to set search query for joining two tables in sql?

What's the wrong with this query? SELECT l.company_name,DISTINCT c.sub_cat_name FROM tbl_listing l,tbl_sub_category c WHERE l.company_name LIKE '%cy%' and l.city_id='2' and l.area_id=23 ORDER BY ...
0
votes
1answer
496 views

$wpdb->prepare with ON DUPLICATE KEY UPDATE

I just took this code from $wpdb Codex page, and modified my existing Insert query: $table = $wpdb->prefix . 'user_req'; $post_id = explode('_', $_POST['post_id']); $user_id = $_POST['user_id']; ...
1
vote
0answers
68 views

Delete duplicate rows from wordpress database where a column is duplicate in phpmyadmin

I have a wordpress table like so (phpmyadmin and MySQL) | id | meta_key | meta_value | +----+-----------+------------+ | 1 | import_id | abc | | 2 | import_id | abc | | 3 | ...
0
votes
0answers
137 views

How to parse meta value from user specific post to google charts?

I'm currently working on a project where i need to visualize the progress of users (fitness). For that i have created a custom post type with custom fields. I want to parse the meta values associated ...
0
votes
0answers
132 views

Delete duplicate posts where meta_key is the same

I have imported some posts and this has caused some to be duplicated Each post (of a custom post type "property") should have a unique meta_key "import__id" value I need to delete all duplicate ...
0
votes
1answer
224 views

$wpdb->get_var - What value is returned when zero records are found?

I have the following code: $queryPermission = $wpdb->get_var( $wpdb->prepare("SELECT Active FROM testers WHERE user_id = '$user_id' ")); ...
0
votes
0answers
118 views

SQL query to remove first image in all posts

I've built a site up over a few years (3,500+ posts) where I've inserted images using the traditional method into the post content itself. I'm now moving to a different theme, and have made the first ...
0
votes
1answer
246 views

SQL to update custom post taxonomies

I have a custom post "review". It uses the same categories and tags from default posts, so they share "category" and "tag" taxonomies. But later I changed the "review" register to have their own ...
0
votes
1answer
270 views

Use wpdb->prepare for `order by` column name

In my current plugin, I am picking up the order by column as user input. So I thought of using wpdb->prepare to escape it. $wpdb->get_results($wpdb->prepare("Select id from $wpdb->posts ...
0
votes
1answer
45 views

Is there a WP function to get taxonomy name from taxonomy_term_id?

I need to get the taxonomy name from the taxonomy_term_id. I am currently using the following to get it: global $wpdb; $term_taxonomy_table = $wpdb->prefix . "term_taxonomy"; $taxonomy = ...
0
votes
1answer
61 views

Do I need to deal with WordPress SQL Injection

Do I need to prepare strings against MySQL Injection when inserting into the database using a WordPress comments function such as this: $data = array( 'comment_post_ID' => $post_id, ...
0
votes
1answer
72 views

SELECT from wp_users, get Displayname too

SELECT post_author, count(ID) as amount FROM dbold_posts WHERE WEEKOFYEAR( post_date ) = WEEKOFYEAR( NOW() ) AND post_status = 'publish' AND post_type = 'post' GROUP BY post_author ...
0
votes
1answer
40 views

How to avoid filling up an array each time I run a WP_query?

I am making a following user system and need some help for retrieving the users ids a user is following. At the moment I am using the following SQL query for retrieving the users ids a user is ...
0
votes
0answers
56 views

All images from posts of specific category

I'm photographer and am developing my own portfolio, it's in the final stage. I'm trying to get all images from posts in a specific category. I can actually get all images from all posts, but they ...
1
vote
1answer
1k views

how to use $wpdb->prepare to update a custom table

As a noob I dont understand a lot of SQL injections but I need to be save so I have read that I have to use wpdb->prepare to make sure the data is stored correct. At this moment I use the ...
0
votes
2answers
46 views

Is it possible to have more than 1 sql databases in my wordpress blog?

I m watching video on installing wordpress manually. on first launch wordpress prompts you to input your sql database name, sql password etc. then i can start working from dashboard. is it ...
0
votes
1answer
16 views

looking for a way to allow users to backup the plugin db data(save as)

I have a custom build plugin and I want to add the option to let the user save the plugin data(not using a thirdparty plugin to do this for me). So if a user clicks on the button it will allow them ...
0
votes
1answer
105 views

How to SQL query posts IDs by categories AND authors?

I am making a custom WP_Query and I need to come up with a SQL query that gets the posts IDs from X categories and Y authors. Then merge those IDs and put them in an array. I only need to figure out ...
0
votes
0answers
93 views

Multiple taxonomy drill down filter on a collection of posts

I would like to add a drill down filter to a product catalog site with one main taxonomy, and three taxonomies that serve as additional filter for the main product category. The main plan is to build ...
-1
votes
1answer
13 views

The page that displays Posts on homepage

I want to know the page responsible for displaying the blog posts in WordPress. Where I can probably expect to find the SQL query and post rendering so I can edit some stuff by myself.
0
votes
0answers
341 views

Custom WP_Query with SQL directives for getting posts by authors and terms

I am making a custom page where I need to display posts from authors and terms (categories). I tried with the built in WP_query arguments but I am not getting the result I want. So I want to know how ...
0
votes
1answer
90 views

Randomly select one of last 3 posts

ok so i have this: $args=array( 'orderby' => 'rand', 'order' => 'DESC', 'posts_per_page' => 1, 'offset' => $offset, ); $q = new ...
0
votes
0answers
19 views

WP query taxonomies not the same as output

I'm trying to build a custom query and I need to include the current category ID. I previously had the WP_Query args as: Array ( [post_status] => publish [posts_per_page] => -1 ...
0
votes
0answers
74 views

Order users by 2 custom fields in wpdb query

I've created a WordPress members site, each member is a user with the role of subsriber and has extra information set as custom fields - ie: address, contact details etc. I have the users output by ...
0
votes
0answers
15 views

error inserting value

Im kinda having some problem in my query and looks alright in my side and tested it in a localhost too. $query = "INSERT INTO$db_name(fname,pass) VALUES('".$_REQUEST['fname']."', ...
0
votes
1answer
101 views

What is the point of get_comment_count() if you cannot limit by a comment type?

We are finding that large WooCommerce sites run very slow. Amongst many issues, this one has me scratching my head. WooComemrce stores order notes in the comments table, giving them a comment_type of ...
0
votes
1answer
23 views

optimise SQL wordpress call

I have this code : $querystr = " SELECT * FROM {$wpdb->prefix}posts INNER JOIN {$wpdb->prefix}postmeta m1 ON ( {$wpdb->prefix}posts.ID = m1.post_id ) INNER JOIN {$wpdb->prefix}postmeta ...
1
vote
1answer
130 views

Query Wordpress database by registered date and role

I would like to get the display name and email address for all users who have registered to my multisite today with the role of subscriber. It needs to be an SQL query as it's used outside of the WP ...
0
votes
0answers
68 views

$wpdb->prepare - supporting multiple search terms

I am trying to write an escaped SQL statement, for example: $sql = 'SELECT * from TABLE where column LIKE %searchterm% AND column LIKE %searchterm2%'; Except I don't know how to handle it, as I do ...
0
votes
0answers
296 views

SQL Query to select post thumbnail, post title, post content from a category

I use the db of my wordpress blog to develop a mobile application in Java. For this, I need the SQL query to display the thumbnail of a post, the title and the content in a selected category. I think ...
1
vote
1answer
71 views

Confused by $wpdb->prepare

I am attempting to use $wpdb->prepare to protect against SQL injection attacks and am lost. I have the following snippet below which checks the h_transactions table for a transaction id. If it ...
0
votes
1answer
64 views

Size article thumbnails and retrieve them directly from database

I've integrated the Wordpress database directly with my .NET application. What I want is to set the featured image of a post. This featured image must be maximum 800pixels wide, and automatically ...
0
votes
0answers
38 views

Genesis framework comments broken?

I got a really weird problem. Im using a Child theme which using the Genesis framework. I was using Akismet plugin to stop the spammers and it was workin just fine. Recently i just made a comment by ...
0
votes
0answers
80 views

Wpdb generates too many queries

I googled for hours, then found some codes on stackexchange (http://wordpress.stackexchange.com/a/108279/108270) and created the codes below. I'm trying to get alphabetical A-Z posts lists (e.g. A B C ...
0
votes
1answer
411 views

Inserting rows into a custom table, when plugin is activated

Trying to create a plugin that creates a custom table & populates it with a row of data, once activated. The table is created OK, but the row of data is not added. Please can someone point out ...