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)

0
votes
1answer
421 views

Speeding SQL queries for a large database?

I am using a WordPress plugin called feedwordpress in order to run a planet like website on wordpress (See it here). The plugin is great except for one thing - it hogs down my (VPS) server into ...
0
votes
3answers
338 views

Problems with moving my Wordpress site to another domain/server

I'm having problems moving a wordpress site from one domain to another. I've searched the site but couldn find a useful answer for my situation. Here's what i did: I made a backup of the website. ...
0
votes
1answer
35 views

Which is better and faster ? Wordpress Queries or SQL Query

Suppose I am developing a minimal theme, the the post page single.php displays only the post title, the excerpt and the content. So in general that would be <?php the_title(); ?> <?php ...
0
votes
1answer
27 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. ...
0
votes
1answer
143 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
263 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 ...
0
votes
3answers
103 views

Get a count of how many times a term or a category is used in posts

I need to find out the number of times a term/tag or category is used in a post in WordPress. I wrote the below SQL query. SELECT t.name , count(*)FROM wp_terms t JOIN wp_term_taxonomy tt ON ...
0
votes
1answer
101 views

How do I insert a new meta key / value pair, but only if another meta key is present?

I need to add a new meta key and value part only on posts where another key is present (regardless of its value). I tried to use a query to automate it, but my SQL is quite limited Here's what I ...
0
votes
2answers
178 views

How to use get_results() in widget front end?

I'm trying to get_results() in my widget's front end, this is my current code: public function widget( $args, $instance ) { echo $args['before_widget']; if($children = $wpdb->get_results( ...
0
votes
1answer
76 views

How to concatenate two separate colums into one?

In phpmyadmin I have two separate columns for latitude and longitude. e.g. lat: '38.897683' lng:'-77.03649'. These coordinates are generated for my location custom posts. How can I automatically ...
0
votes
1answer
243 views

Custom SQL query ORDER BY term_order

I have custom taxonomy that list terms under "series" that contain posts that are also present in terms under "media_type" and where media_type is term_id 16. I want to order the list by the ...
0
votes
2answers
150 views

Really simple query giving error in SQL syntax

I'm sure this is a simple oversight but I cannot seem to narrow it down: global $wpdb; $tablename = $wpdb->prefix . "icrm_folders"; $sql = $wpdb->prepare( "SELECT * FROM %s", $tablename ); ...
0
votes
1answer
62 views

Custom $wpdb returns unexpected time based results

I am using the $wpdb class to do a custom SQL query but I am getting weird results. Basically this is what my SQL query is supposed to do Retrieve the titles of post_types 'question' only if they ...
0
votes
1answer
353 views

pull data from a remote wordpress database

I am trying to pull some data from a remote wordpress database. Here is the code I have: $server = "my server code"; $user = "my username"; $password = "my password"; $db = "mydb"; $con = ...
0
votes
1answer
43 views

How to migrate a database from a server to another

I try the export method of phpmyadmin, but the user is exported with the data... so there is no way to re import it into another database without error message. The old user is name : ...
0
votes
1answer
96 views

Proper approach to moving complete site from one domain to another AND preserve widgets

I consider myself fairly versed in this matter, however I've recently had a rash of issues when moving sites. I am able to successfully move the site, edit wp-config.php, move the database, etc. ...
0
votes
1answer
46 views

Removing posts by sql

Often i build a site and we have test posts. I was wondering if there's a way via sql to drop all the blog posts with a simple sql query. Obviously, I would have backed up my previous database before ...
0
votes
1answer
1k views

Export SQL query based on post type

I'm looking to export only wp_posts where post_type = post. Is that possible?
0
votes
4answers
1k views

I need a SQL command to delete specific authors and all posts connected with them

I unfortunately have authors with a lot of unreadable/spam posts published (thousands some of them) I have tried deleting through admin,but its a slow painful process-does anyone have a specific SQL ...
0
votes
1answer
18 views

wpdb getting avatars and author url

Running an SQL query to pull authors by votes they've received on posts. @bonger helped me out on my first post and helped me get this working great, but I created this new question since it's a ...
0
votes
1answer
68 views

$wpdb select date range of posts

0 down vote favorite Using this SQL query to sort users by how many votes(meta key) their posts have received. <?php global $wpdb; $results = ...
0
votes
2answers
96 views

mySQL queries are executed twice on wordpress website

I'm sorry for my english. I'm trying to add some functionalities at my Wordpress website and to do this i have added a function in my function.php theme. The idea is to save in a custom table some ...
0
votes
1answer
42 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 ...
0
votes
1answer
53 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
119 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
1answer
52 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
56 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
39 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
1answer
83 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
56 views

How to optimize multiple insert into wordpress database

I had main file with my plugin and the another file with sql command. In the second file I create two tables and write data to one of them. But I have problem with. In my private computer everything ...
0
votes
1answer
121 views

How to display data from db in select list [closed]

I wonder what it's wrong in my code. I can't get all of data in column "adres". In result I only have the lest record. Thanks for help. global $wpdb; $result = $wpdb->get_results ("SELECT ...
0
votes
1answer
57 views

Help me SELECT thumbnail from SQL and use

//MySQL Username $user = "myuser"; //MySQL Password $pass = "mypass"; //MySQL Database Name $database = "mydb"; //Number of posts you want to have appear $numOfPosts = 7; //Setup connection $mysqli = ...
0
votes
1answer
228 views

Select column name dynamically mySQL Query

$country="USA"; $dr=$wpdb->get_results("SELECT $country FROM wp_shipping WHERE ID=$ids"); I want the above query in WordPress file, where country name is given dynamically but I am not getting ...
0
votes
1answer
83 views

wpdb_prepare with multiple or condition

I want to execute a query like this: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string ); If I do the query with only one ...
0
votes
1answer
56 views

For a complete backup, is it enough to copy htdocs and export database?

I copied the htdocs via FTP from the server which hosts my wordpress blog. Moreover, I used phpMyAdmin to export the MySQL database. When I move to a new server, can I just create a database, run the ...
0
votes
1answer
38 views

Wordpress SQL - How to Check for Category?

I'm using the following SQL (wrapped in php) to find posts in a wordpress database: $sql = " SELECT p.* FROM {$wpdb->prefix}most_popular mp INNER JOIN ...
0
votes
2answers
2k views

Getting value from database table depending on field value

I am using a plugin called formidable which is similar to Gravity Forms in terms of purpose. I have two fields of interest. The first field loads up all the values in the Town column of my ...
0
votes
1answer
234 views

SQL: Select wordpress posts with given text string and add a custom field to them?

I want to select all wordpress posts that have a certain text string. Then to add a custom field to all those posts. Here is what I figured out so far but it doesn't work INSERT INTO wp_postmeta ...
0
votes
1answer
102 views

An action hook where a comment meta is updated

By analogy to the hook on post meta update, I use the following code for hooking when comment meta value is updated. My comment meta key is "consider" and can have 2 values: 0 and 1. My Goal is to ...
0
votes
2answers
127 views

count number of user comments with a specific comment meta value

I am using the code below to count the number of comments by a certain user: global $wpdb; $count = $wpdb->get_var( 'SELECT COUNT( comment_id ) FROM '. $wpdb->comments .' ...
0
votes
1answer
57 views

count number of all comments by a user on different (non-repeated) posts

I thank you in advance for your help. I am using Wordpress for about 2 years, but always avoiding SQL inside my scripts and looking for built-in functions to perform my goals. To count the comments ...
0
votes
1answer
159 views

wpdb prepare sql problem

I have problem with wpdb prepare and sql query. If i run the query directly thru wpdb->get_results it's working fine. Here it is: $alabala_sql = $wpdb->prepare( " SELECT * FROM ...
0
votes
2answers
117 views

making php value numeric

I used some of this code from this page on Stack Overflow: Using wp_query is it possible to orderby taxonomy? It's about the function to be able to sort a query by a taxonomy value. Although it works ...
0
votes
2answers
73 views

How can I get all author written content?

I have a site that needs two different tabs: 1. all author written content (Posts, comments, CTP) 2. all author followed content (categories, taxonomies, other users content) For the first all I ...
0
votes
1answer
76 views

How do I query for posts by custom meta and those that have been stickied?

I realize how clumsy and inefficient this query is but SQL is not my strong point. I use the following query to pull the latest 8 events from a custom post type called Event Posts. However, I also ...
0
votes
1answer
188 views

Using color schemes with Color Picker

What I'm doing User interface to change website colors - User can change colors individually (like menu color, footer color, content color), or use color scheme that will change all colors (values ...
0
votes
1answer
97 views

Print page content with formatting when doing custom SQL query

I guess there's a simple solution for this but couldn't find any. I'm trying to fetch 3 pages and show them on footer. The problem is that every page is shown as text without formatting which means ...
0
votes
2answers
1k views

SQL query to get posts from multiple categories but not in a category

I need to get the last posts' ID and the post_tile within categories 1 and 2, and exclude those within category 3. It must be SQL, because if I use WP_Query it retrieves too much info and I only need ...
0
votes
1answer
382 views

Wordpress SQL JOIN query

Hi Im trying to run 2 querys in the same query call. // send the query global $wpdb; $commentQ = "SELECT * FROM $wpdb->comments " . $whereClause . $orderBy; $comments = ...
0
votes
2answers
78 views

How to delete ALL comments from certain category in Wordpress database?

I'm trying to delete all comments from posts in a certain category in a Wordpress database. The Wordpress database is rather complicated so this must be probably some join of wp_posts, wp_comments ...