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).

-1
votes
1answer
15 views

query using wpdb in wordpress gets me no result

I get no result unless i cut the string title to "Gocomma 10W QI Wireless Fast Charger Car Mount Holder " ... $title1="Gocomma 10W QI Wireless Fast Charger Car Mount Holder - 2pcs (it)"; $...
0
votes
1answer
27 views

Collect all events in one year

Hello can you help me I can't do this: 2018 event 1 event 2 My current output: 2018 event 1 2018 event 2 I want do this without GROUP_CONCAT() ...
0
votes
0answers
18 views

MY database error Lost connection to MySQL

Am getting this error, please help
0
votes
0answers
21 views

My website frequently redirect to a different advertisement URL

Can you guys help me to figure out why it's happening? Its mainly happen from my search engine result. From Google search when I click on my website it will redirect to a scam website. Note: now its ...
0
votes
0answers
16 views

Code to insert TAG taxonomy Wordpress

I made a grave error. I delete many TAGs from the database of my blog. Many TAGs were orphaned. And yet, unfortunately, many posts have anchor words that link to deleted tags. That is, several links ...
0
votes
0answers
10 views

SQL to Query the db and return all posts and it's metas

I am trying to query the wp db and return all posts and it's metas. However, the return is very slow. Am I doing it the right way to get the most optimal results? Please see my SQL below: SELECT ...
0
votes
0answers
26 views

Translating WP query into to SQL query

I have very complex wp query and I want to use sql query instead of this. Is there any way to translate wp query to sql query. I am thinking that I will have a better control over sql query as the wp ...
-1
votes
0answers
14 views

SQL: how can do UPDATE on a SELECT query?

how can I do I UPDATE wp_posts SET post_status = 'draft' on this query below: select bad_rows.ID, bad_rows.post_title, post_type, meta_value from wp_posts as bad_rows ...
0
votes
1answer
20 views

SQL query: select duplicate posts - but using duplicate meta [duplicate]

how can I select the duplicate freelancer.com posts? post_id meta_key meta_value -------- ------------------- ---------------------------------------- 1 ...
1
vote
3answers
37 views

List of the years with posts presented

I need to get a list of the years with posts of given category. Like this: 2008, 2009, 2010, 2012, 2013 (if there were no posts in 2011, it's not included). I try this query, and it works — I get my ...
0
votes
0answers
25 views

how can I use SQL query to find duplicate posts using duplicate meta value instead of post title

I am using wordpress to syndicate RSS feeds and I get a lot of duplicates, however most duplicate plugins only check for duplicated post title. This is no good as posts often have the same title but ...
1
vote
1answer
10 views

batch adding posts to a category based on matching regex for title with SQL

I am adding location categories to posts based on keywords in title (with regex), I got it working once, so code is fine the first time, but now get SQL Error (1062) Duplicate entry '4419-268' so I ...
0
votes
0answers
21 views

Wordpress search query, how to modify the sql

I have a problem with the query search, which means I would only look for posts with post_status = published. The problem is that after adding my conditions, wordpress writes an "OR wp_terms.name LIKE%...
0
votes
0answers
19 views

Post title value with colon causing search issues

Hoping someone can help shed some light here... I have the following titles: Icons & Innovators: Norman Lear Muslim/American: Halal 44 Charlton: Pride I am using the native WP search. The ...
0
votes
0answers
12 views

Possible to connect Metabase to a WordPress SQL Database?

I am hosting with WPEngine and I have a lot of customer data that I'd like to interact with. My question is - does anyone know if it possible to connect Metabase with a SQL WPEngine hosted database? ...
0
votes
0answers
24 views

Reset post IDs with all post meta

I imported posts from an old website. Posts from the new website have IDs under 100. Posts from the old website have IDs above 9934. I tried to change manually the post IDs in phpmyadmin in order to ...
1
vote
1answer
26 views

How to Order by random on a SQL query

How do I change the last line to order by rand? Now it's sorting by date of my woocommerce products. INNER JOIN $wpdb->postmeta AS mt1 ON (posts.ID = mt1.post_id) WHERE posts....
-1
votes
1answer
32 views

SQL Query : how copy all tags of post into their post content in wordpress by sql query

I want to copy/move all tags of a post into posts content, as text form not in a link form. For example: A post has: a title in title field, some content in content field (like: a ...
0
votes
1answer
31 views

Query where ANDing slug values not working

I realize this isn't the most elegant sql. I modified this query where the original query only selected from a single category (the slug field of the terms table). I am trying to obtain a result set ...
1
vote
1answer
16 views

Multiples Empty Posts were created and cannot delete them

Over 2000 empty posts were created and I cannot delete them from the admin. Couldn't find them on SQL either using SELECT * FROM wp_posts a LEFT JOIN wp_term_relationships b ON ( a.ID = b.object_id )...
1
vote
1answer
56 views

Get stock by custom meta field on all Woocommerce variable products

In WooCommerce, I have a custom meta field "Brand" on my products, and each product is assigned with one of the Brands. Now I want to get total stock for each brand from all products and I have only ...
0
votes
2answers
16 views

correct validate and sql query

Is this method of operation on the database is safe and correct? if(isset($_POST['name'])){ $table = $wpdb->prefix.'_my_table'; $post = trim(sanitize_user($_POST['name'], true)); $...
0
votes
1answer
28 views

Migrate posts from category and sub-category via SQL

I am trying to migrate all contents from a category to another using SQL. Thanks for help. I want to change the term_taxonomy_id of this query.
1
vote
0answers
28 views

get search results from only specific page name in wordpress

I have created a page by using add_submenu_page: add_submenu_page( "pharma-plugin", // parent slug "All Trade Name", // page title "All Trade Name", // menu title "manage_options", // ...
-1
votes
1answer
26 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
23 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
30 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
16 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
22 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->...
2
votes
2answers
164 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
44 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
19 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 > ...
4
votes
1answer
50 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
20 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
79 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
16 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
30 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
30 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
29 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
27 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
59 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
174 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
27 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
20 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
28 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
12 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
34 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
30 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 "...