Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [sql]

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

0
votes
1answer
14 views

correct validate inputs

How correct validate data from user to save in database from inputs? I use this for textfields: $name = trim(sanitize_text_field($_POST['name'])); But if i add special signs like "&*({} ...
0
votes
1answer
18 views

problem with sql query

I have a problem with quotes with query. My code: $this->table_name= 'table_name'; $how_much = $this->wpdb->get_var($this->wpdb->prepare("SELECT COUNT(*) FROM {$this->...
0
votes
1answer
24 views

correct sql query

I wrote database queries some time ago and now I would like to improve them. But something I do wrong and i need help. class tags{ private $wpdb; public function __construct(){ ...
0
votes
2answers
14 views

WordPress filter from custom table is not working properly

I want to filter the exact information from a custom WordPress table no matter the user has filled all the text boxes or not. I have used a LIKE query but it`s not working properly if the user left ...
0
votes
1answer
16 views

How to get INSERT errors from $wpdb?

I have these $wpdb->suppress_errors(false); $wpdb->show_errors (true); $wpdbp = $wpdb->prepare($preparedQuery->query, $preparedQuery->values); $result = $wpdb->...
-1
votes
0answers
16 views

What is considered ‘the limit’ size of a WP Database?

Please don’t downvote - I am genuinely asking for advice and help and yes I have sought advice from other sources. Thank you for wanting to help. I anticipate that my WP install we get to possibly ...
2
votes
2answers
154 views

Is there a (better) way to access $wpdb results?

I have this: global $wpdb; $wpdbp = $wpdb->prepare('SELECT EXISTS ([some query] WHERE user_id =%d);',$target_user_id); $result = $wpdb->get_results($wpdbp); I want to know if the ...
0
votes
1answer
26 views

Search database with WPDB using a php variable

I'm trying to do a basic search feature for my website database. I want to search the text content inside a custom database table using Wordpress and WPDB. For some reason the search is not returning ...
0
votes
1answer
18 views

SQL query, error

I have sql query but not work, i have notice: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'WHERE custom > ...
5
votes
1answer
41 views

Is it possible to select against a post's parent's fields with WP_Query?

I'd like to query post revisions using WP_Query for display on an admin page, and I want to include pagination parameters. I have two constraints: I would like to only retrieve revisions for ...
0
votes
0answers
11 views

WPDB Get Array Of Taxonomies With Post Count

I'm trying to get an array of taxonomies with the count of post types using $wbdb. I would like my array to be: [ [term_name] => [post_count_by_term] ] I've started setting up my SQL query, ...
0
votes
0answers
14 views

WordPress database error Lost connection to MySQL server during query for query SELECT SQL_CALC_FOUND_ROWS

I have Wordpress Blog with [Goodnews Theme][1] version 5.9.5 (the latest) Recently it shows the following error [05-Apr-2019 11:10:17 UTC] WordPress database error Lost connection to MySQL server ...
0
votes
0answers
10 views

Woocommerce: sql pivot row to column for orders

I'm trying to write a query which grabs associated order_itemmeta with orders. What I have works well but it only returns a single row. I need it to return all order instances of 'summer bay high ...
0
votes
0answers
18 views

how to insert/ import wp custom post type data manually into database

I have created a custom post type with a few custom fields in WordPress. I need to insert this custom post type data manually insert/ import into database table from my another table. My custom post ...
0
votes
2answers
17 views

How do I loop/iterate through posts to edit all img tags?

Heads up, I'm pretty new to Wordpress... But I need to loop through multiple posts and change all 'data-src' attributes to 'src' so my images will display. What's the way/best way to go about doing ...
2
votes
2answers
22 views

Get post from meta_key and meta_value

I have this sql statement: SELECT post_id FROM wp_postmeta WHERE meta_key = $param1 AND meta_value = $param2 I am facing one problem: I don't know how to do that sql code with wordpress ...
0
votes
1answer
22 views

The paging is very slow under a large number of articles

How can I optimize sql? SELECT wp_posts.ID FROM wp_posts LEFT JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE 1=1 AND ( wp_term_relationships.term_taxonomy_id IN ...
0
votes
1answer
25 views

SQL query to delete users with multiple meta keys and comments

I need help putting together an SQL that can delete users if they don't have (metakey1 or metakey2) and (does not have comments) I have this SQL which does it for single meta_key SELECT * FROM ...
1
vote
1answer
49 views

Get posts by category with pure SQL query

I have a meeting post type, whose titles automatically get set to a date of the form m/d/Y. I have the below query which gets all unique years from the post titles by selecting distinct values after ...
0
votes
0answers
145 views

Wordpress MySQL Search and replace with wildcard?

I'm trying to search and replace for a link with wildcard in phpMyadmin. If I simulate this query UPDATE wp_posts SET post_content = REPLACE (post_content, '<a style="text-decoration:none" ...
0
votes
0answers
24 views

How do I get data from my database into my Custom Export Field

I am trying to get data from my database to export to a XML or CSV File by using a custom query. This is my function with the query : <?php function get_workhours($ID){ $sql = $wpdb->...
0
votes
1answer
19 views

How to remove massive link in WordPress content

I would like to delete certain link that I have in the content of all the entries, for example : <a href="https://www.sitio.com">link contenido</a> Change it to: link contenido Or ...
0
votes
1answer
26 views

How to show result of sql query in a page?

I have a table in the same DB that I have a WordPress page and I want to show in the land page the count of total of rows and then I need an another page that show the information of this table , How ...
0
votes
1answer
10 views

Options on how to Display member specific data from a MS SQL database

I am in the conceptual stage still but I want to create a word press database that will do the following in the following scenario: Lets say i have 10 sales people in my store. I want them to be ...
0
votes
0answers
17 views

Sending WordPress Data (API) to SQL table

Looking for a solution that can send our WordPress checkout data to a local SQL database in certain table. We have custom form to capture data needed from user for our YII application, just no way to ...
0
votes
0answers
31 views

WHERE on meta key SQL

Given this working query: SELECT `p`.`post_title` AS 'Auto', MAX(CASE WHEN `pmd`.`meta_key` = 'regular_price' THEN `pmd`.`meta_value` END) `Prijs`, MAX(CASE WHEN `pmd`.`meta_key` = 'aankoop_datum' ...
0
votes
1answer
20 views

SQL query to change the value of a Custom Field

I am looking for a SQL query to change the value of a custom field, but not on all posts. Some posts have in the "post_template" custom field a "temp1" value, and I want to change this value to "...
0
votes
1answer
48 views

Debugging wp_query orderby for taxonomy

I cannot seem to find where WP_Query adds the orderby clause to a SQL query. I am using this code: function wpd_team_taxonomy_queries( $query ) { if ( !is_admin() && $query->is_tax( 'team'...
0
votes
0answers
12 views

Can I replace the “Upgrade Network” with SQL query?

I have a WordPress Multisite network. When the WordPress version has been updated, I have to click on "Upgrade Network" for do same thing on all subsites. How can I replace this function with one SQL ...
0
votes
0answers
18 views

Relations between taxonomy terms for getting parent child nested Json objects and arrays

i have 2 taxonomies (cat) (subcat) and they have some terms(rows) for example , , i want make a relation like SQL data tables between the taxonomy terms for giving me a nested object of arrays in the ...
0
votes
0answers
13 views

Woocommerce - insert cart data to a a secondry database on a different server

so here is my situation I have a eCommerce website built with Woocommerce - wordpress that is hosted on Godaddy php server, and I also developed an ASP.Net application to serve couple of other ...
0
votes
0answers
20 views

Using a meta_value or postdate to to query and orderby

How do I structure a sql that: 2 checks if meta_value is in future or has no meta_value at all and 1 orders by meta_value (meta_key => datum_event), and conditionally if this meta_value is empty ...
2
votes
1answer
73 views

WPDB: how to get the value of a field in a custom database table

For my WordPress site, I would like to echo the value of a column in a row (determined by the user's ID) of a table in the database for my site. This table was created by a plugin so it is not ...
0
votes
0answers
12 views

Create user with sql if it does not exist in wordpress

Forgive me if I'm in the wrong place, I'm digging the Stack Exchange world. This functional sql code creates a user in wordpress: INSERT INTO `wp_users` (`user_login`, `user_pass`, `user_nicename`, `...
0
votes
1answer
25 views

Query post with meta_query where date is not in future

In my args I would like to exclude posts where the datum_event is not in the future. Currently it only displays posts with datum_event values that are in the past, but because older posts don't have ...
1
vote
1answer
23 views

Databases - Submitting data from inputs to database [closed]

I am attempting to submit data to a table I have created within my database. For sanity sake I have called it 'wp_email_subscribers'. Including the wp_ prefix. I know there is a way to insert data ...
0
votes
1answer
42 views

Help posting values to DB on submit using $wpdb->query

I am not new to WordPress but this is the first time I have tried to use the $wpdb. I have set up a form: <form method="post" action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']);?>"...
0
votes
1answer
54 views

Is it possible to query from external database? [duplicate]

I have an extarnal database that I want to show some data in my wordpress site. What are the necessary steps to achieve this? edit: I changed config.inc.php according to https://stackoverflow.com/...
0
votes
0answers
22 views

What's the easiest way to connect external database and display data on wordpress?

I want to use google cloud sql for keeping my data. The data is changeable from another application. I give necessary permissions to cloud sql but I cannot find easier way to show the data on the ...
0
votes
0answers
15 views

Moving attachment postmeta rows to new database

I am moving a lot of content from one existing (and damaged) Wordpress installation to another existing installation. I am trying to bring the media library attachments into the new site, but when I ...
1
vote
1answer
34 views

Including metaboxes from custom post types in global search — continued

I've seen several questions about including the content of meta-fields in a wordpress search. My question is not a duplicate of these. Background The issue I'm having stems from how meta queries ...
0
votes
2answers
26 views

Build filter for post-type + multi taxonomies + multi terms

I Need to build an interface with a filter set (a list of checkboxes) that the user can check and click 'filter' to search with in 1 custom post-type for posts with matching terms (there are 3 custom ...
1
vote
1answer
163 views

Order by summing multiple values

In a custom post type (products) I want to order products by summing multiple values based on user selection. I use custom taxonomies to filter the products. I could use the orderby meta_value but ...
0
votes
1answer
60 views

Is it best to avoid using $wpdb for security issues?

I'm using WordPress Multisite with multilingualpress. In order to get the href, outside of my navbar, to the page with the appropriate language, I am using an SQL query that queries $wpdb within the ...
1
vote
1answer
38 views

Renaming post IDs - Okay to do?

Is it possible to change the post IDs within the wp_posts table without causing problems? I ask this because I have a WordPress Multisite in which I separate the sites by language. Unfortunately, the ...
0
votes
1answer
26 views

update_option returns false in AJAX, how to debug?

I tried debug plugins for WordPress, but they only show the current page SQL queries. How to debug if update_option returns false? I am updating an object decoded from AJAX request with json_decode ...
-2
votes
1answer
31 views

why you don't Implement PDO for access every thing to database

that is.. why wordpress don´t use PDO if it is more secure, and prevent a lot of injections, and issues with security. Thakns
0
votes
0answers
25 views

Get count of each category depend on date - SQL query in WP

I would like to select all categories of my blog with count and date of create. I know that I have to convert post_date to specific month and then group my select by month(date) and category. However ...
0
votes
1answer
29 views

How to copy user_nicename value into user_login

a hacker put value "admin" into all user_login fields. i need to copy user_nicename value into the user_login so users can login. is there a SQL command i can run to do this task in bulk, as their ...
0
votes
1answer
22 views

I can't figure out what's wrong with this statement. $wpdb->query update

I'm trying to use the $wpdb-query method, but can't seem to get it to work. I get a 500 error when I try the following: $update_status = $wpdb->query($wpdb->prepare("UPDATE {$wpdb->prefix}...