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

Filter by
Sorted by
Tagged with
0
votes
2answers
25 views

How to Assign / Move all Deleted post to a category

I have a database of 50,000 articles, One of my categories contains post of 30k, I mistakenly Deleted a category that contains 30k Post, But all the posts still exist. I have search google for the ...
1
vote
1answer
342 views

Get the exact SQL query that get_posts() generated

I am working on a WordPress that someone else started and then disappeared. She created a few custom content types and variables using different plugins and I now want to access the data sets in the ...
0
votes
2answers
28 views

How to get EVENT based on startday, using BETWEEN

I have a SQL query that get all events ordering by Startdate, and i define startday as $today. but this query didn't take events that start yestarday and that endday is tomorow. how can i make my ...
0
votes
1answer
43 views

SQL - Shorter way to query user and usermeta data

I'm looking to query a bunch of user and usermeta data into a single table. I'm able to do so by creating multiple temporary tables and a pivot: create temporary table meta select u.ID, u....
0
votes
0answers
14 views

WP SQL sintax to filter by multiple criteria

Ciao guys, I am trying to get products by an $wpdb->get_col() SQL query, but I am in trouble with the SQL syntax. I need products which have an exact category and IN at least one taxonomy terms. ...
0
votes
1answer
34 views

Why does changing Database Table Prefixes result in loss of content?

As to add an additional layer of security, to an eCommerce website I am working on, I have changed the default Database prefix from wp_ to wp_additional_prefix. To do this, I opened the wp-config....
0
votes
2answers
191 views

How to create multiple database tables on plugin activation?

I have an activation hook to create 2 new database tables that don't exist, only the second table is created from this code: public function add_tables() { // Global $wpdb ...
0
votes
1answer
109 views

update acf field value using sql query?

Any example to update acf field value? I am newcomer in acf fields. I need to use sql code. the field is numeric and the name is “totalviews”. I want to update the totalviews by +1 using sql only ...
-1
votes
1answer
17 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
30 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
21 views

MY database error Lost connection to MySQL

Am getting this error, please help
0
votes
0answers
36 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
19 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
11 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
72 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 ...
0
votes
1answer
63 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
75 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
174 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
15 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
216 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
66 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
42 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
38 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
40 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
33 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
17 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
425 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
27 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
97 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
34 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
27 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
37 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
35 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
29 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
76 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
352 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
231 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
24 views

SQL query, error

I have sql query: $query= "SELECT * FROM files ORDER BY id DESC LIMIT $from, $site WHERE custom > 0"; but not work, i have notice: You have an error in your SQL syntax; check the manual that ...
4
votes
1answer
78 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
42 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
248 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
23 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
97 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
28 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
522 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
61 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
42 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
278 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
469 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" ...

1 2 3 4 5 14