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
1answer
626 views

SQL query to set posts in bulk based on the post content

I have thousands of offline links in my posts, and I'd like to set them all to draft. I know the links are in the format example.com/fileX. So I needed a SQL query to search the post content and ...
0
votes
1answer
58 views

How to set posts to draft in bulk based on the content of the post

I have thousands of offline links in my posts, and I'd like to set them all to draft. I know the links are in the format example.com/fileX. So I needed a SQL query to search the post content and ...
0
votes
1answer
134 views

How do I display SQL query on a specific page of my wordpress site

this is the query i want to display SELECT account_number, consumer_name, bill_amount, due_date, disco_date, bill_status FROM wp_bill_inquiry WHERE account_number = input AND pin_number = input by ...
2
votes
1answer
111 views

Using table lock with wp_insert_post?

I'm running a cron every 5:th minute that inserts a lot of posts. Sometimes it happens that those crons are running both at the same time. To be sure that not causing duplicate posts. I would like to ...
0
votes
1answer
320 views

How to create index (sql) to a meta_key?

I am new in programming, and the sql is absolutely stranger for me. I create today a new meta_key on my multisite, but when I use this in a query, my site will be horrible slow... I read (here: https:/...
0
votes
2answers
210 views

Bulk update set of URLs via SQL

I've checked multiple questions and can't seem to find the answer. How can I update a list of URLs to either include "-google" at the end of the permalink, or set the URL to a custom url. My list of ...
1
vote
0answers
62 views

The function can not create a table on MariaDB server

The function works on MySQL server well but it can not create a table on the MariaDB server. What could be the problem? public function create_table() { $current_version = get_option('...
0
votes
1answer
335 views

Pull MySQL data from multiple tables and merge into 1 PHP array

Appreciate help in advance. I am dealing with a bit of a pickle with a formula. I am trying to create a page template that will display a list of users, specific metadata from usermeta table + ...
0
votes
0answers
18 views

Wordpress database issues - menu not saving correctly, media thumbnails not showing

I am having a problem with Wordpress that I have not ever seen before. I when make changes to any of the menus on my site, they don't save correctly. For instance, I will add a page to the menu, and ...
0
votes
1answer
37 views

Custom Search | check multiple meta_value for search value

I am going to split up my following question in two sections and make it more neutral, so people can look it up and find it if they have the same question, rather than making it too specific ... I am ...
0
votes
1answer
59 views

searching by keywords in post's metas or pagination links problem

i wanna create a custom search that will search posts by keyword not only in their titles and/or contents, but in post metas. for example, from $wp_query->query_vars['s'] i got a word 'plastic' after ...
0
votes
1answer
20 views

Changing an array of IDs in the usermeta table to fit different format

A site I'm developing used WP Post Favorites to store post IDs in the usermeta table. I'm now trying to port this data over to a new site (the users and usermeta tables have been migrated over), but ...
0
votes
1answer
26 views

How can i restore only Blogs from a SQL backup file?

I have taken backup of full DB from PHPmyAdmin. All other files have been restored successfully. But few blogs didn't come. Now I want to restore only Blogs. Please tell me how??
0
votes
0answers
329 views

Slow wp_posts and wp_postmeta query using Advance Custom Fields

I have a particularly slow query (around 2.2 seconds) getting custom posts (Previews) which are for an event after a certain date and are set as featured (both custom fields stored in wp_postmeta). ...
0
votes
1answer
49 views

How to search CPTs in draft using get_page_by_title()

I'm aware that get_page_by_title() is not an option when you want to look for posts (or CPTs in my case) that are not published (i.e. in draft). Some of the solutions that I've found are based on SQL ...
1
vote
1answer
46 views

How to extract specific post

I've to extract only the posts where the meta_value does't contain some specific string. I use this code: $query = new WP_Query( array( 'post_type' => 'estate', '...
0
votes
0answers
20 views

How to refactor DB queries for better TTFB in WordPress?

I was advised to do 3 things to improve my WordPress TTFB: Upgrade PHP --- It is already 7.0 (apt-get update -y && apt-get upgrade -y didn't change it from 7.0 last time I checked). Use ...
0
votes
1answer
134 views

How to process a single attribute in a SQL request twice times?

I have created a shortcode with only ONE attribute, but the SQL request needs TWO attributes for %s, because of the subquery. The following SQL does not work, because the second %s does not have a ...
1
vote
0answers
154 views

dbDelta not creating table (yes, once more)

I KNOW there are other posts relating to my issue, i read all of them and tried to see if the answer would change and tried a few ones, but I can't seem to create my table using it. Here's my code (...
0
votes
2answers
32 views

Making a query to the DB using same parameters of loop

So, I have a loop that works great. But I need to count how many posts that loop has, and I need to do it via a query to the DB. My loop looks like: $adsArg = array( 'offset' => $...
1
vote
0answers
113 views

Wordpress Database Huge wp_usermeta Table

I have a wordpress site with over than 700,000 users. Each user adds more than 20 rows to the wp_usermeta table ! this is causing very slow queries and the website started to crash, login failure and ...
0
votes
1answer
288 views

SQL query : Select a thumbnail for a media

I'm doing a custom gallery for a portfolio page in a website and It works well if I simply use the URL of the media uploaded this way : SELECT * FROM wp_posts AS p INNER JOIN wp_postmeta AS m ON p....
0
votes
1answer
35 views

Make a loop to return x number of posts, but only if they have content or excerpt

I have tried adding a custom filter around my query, using: $where .= ' AND ' . $wpdb->posts . '.post_excerpt IS NOT NULL AND ' . $wpdb->posts . '.post_content IS NOT NULL'; but that doesn't ...
0
votes
1answer
132 views

WP_Query: apply an SQL function to meta fileld value

Say I'm doing a query with ordering by meta field: new WP_Query( array( 'meta_query' => array( 'state_clause' => array( 'key' => 'state' ), ), '...
0
votes
1answer
38 views

Get category from slug list

I've a list of url's and I want to get the categories of each one. Whats the best way to achieve this? Thanks. Diego
0
votes
1answer
25 views

query sql-table and change entities

i'm writing a plugin and want to change entities based on a sql query. function showTest() { var result= "<button onClick='query(\"wp_users\")'>users</button>" . "<...
0
votes
0answers
132 views

2 $wpdb queries causing error Table 'wp_postmeta' is specified twice, both as a target for 'UPDATE'

I am attempting to run an SQL query on the post meta twice to update 2 values, I get the error: Table 'wp_postmeta' is specified twice, both as a target for 'UPDATE' and as a separate source for data ...
0
votes
2answers
608 views

WP MultiSite: Can't select database error after changing to new domain

I've been developing a WP Multisite on a temp URL for some time now. The site is ready, so I changed my settings around, did a find and replace in SQL from the temp domain to the permanent domain, ...
0
votes
1answer
25 views

Is it possible to utilize custom SQL for a single-post.php?

Is it possible to utilize custom SQL in the single-page.php file to return the desired single post's data? For my purposes, there are data manipulations in the $querystr that are not easily ...
0
votes
0answers
47 views

Improving performance of SQL sub-queries in WordPress

We're using WooCommerce and WooCommerce subscriptions with approximately 23K users. While this question doesn't require that a user be using those plugins, I'm generally wondering how to better ...
2
votes
3answers
88 views

Query to get the author who having maximum number of post (custom post type)

I need to get the author information, who having maximum number of post(custom post type). Here is the code I tried to get the result. $author_query = new WP_User_Query(array ( ...
0
votes
1answer
120 views

WordPress website loads more posts than expected

On the homepage of a WordPress website the latest posts are visible. In the dashboard it's set to display 10 posts on the home page. However, it loads 133 posts. Switching to the default theme didn't ...
6
votes
1answer
262 views

Get Post ID by Content

I am trying to get a post ID by it's post content. I have a custom post type of 'membership' which has post_content that looks like this... {"member_id":33} I am trying to get the ID of this post ...
0
votes
1answer
27 views

Custom Table doesn't create on plugin activation

I'm a newbie in plugin development. I tried following this documentation: https://codex.wordpress.org/Function_Reference/register_activation_hook I've created a function on the main plugin file (wp-...
0
votes
1answer
229 views

Inserting other fields to existing registration form in a WordPress theme

I wanted to add extra fields to my website's registration form but when I test it by creating a new account, the rest of the fields do not update with the registration. It was just Email, Username and ...
1
vote
1answer
102 views

WordPress and MySQL: how to transfer Meta_key and Meta_Value from one post_id to another

I have a lot of meta_key and their relative meta_value associated to a post, for example, post_id = 4319. How can I assign, using an SQL query, all the values to another post_id? for example, post_id ...
0
votes
1answer
529 views

The function is deprecated; use mysql_real_escape_string() instead

I don`t know coding. I recently my website stop to work properly. I get this error on the top of on every page loaded. Deprecated: mysql_escape_string(): This function is deprecated; use ...
0
votes
1answer
292 views

Woocommerce order_complete email dont send after changing order status via sql

I wrote a program that automatically fullfills my orders from woocommerce. After having fullfilled the order I changed the order_status from the order to "wc-completed" via sql. Everything works ...
1
vote
1answer
586 views

How do I find which articles are missing a featured image in The WordPress database?

How do I search the database to find out which articles are missing a featured image on them? I looked around in the wp_posts table and searched post_type is equal to article. It gives me a list of ...
1
vote
1answer
42 views

How to generate page content from database the right way?

I am creating many pages and store them into the database. I am first styling them and than storing them. The idea is to use page.php to check the page id and display the needed post. This is all good,...
0
votes
1answer
147 views

Delete all users meta that named: user_avatar

I want a code like this: UPDATE `jnkdadb7a_usermeta` SET `meta_key`='x1' WHERE (`meta_key` = 'x2'); I want a SQL command to search inside jnkdadb7a_usermeta table for meta_key (X) and delete it.
0
votes
2answers
480 views

wpdb LIKE request shows all database data

I would like to get a list of user_nicenames and the ID. But not all the usernames which is what i'm getting now. I understand I should use the % before and after the $name only nothing seems to be ...
1
vote
1answer
297 views

How to display user_nicename and usermeta values by custom query in Wordpress?

I am trying to display user_nicename and one of usermeta values where meta_key is description. My query is given below: <?php $querystr = " SELECT * FROM $wpdb->users, $wpdb-&...
0
votes
0answers
87 views

Speed up search query that searches in post meta?

I have a rather big query I'm executing (due to clients request). The original search was super slow due to inclusion of WPML tables, so I used posts_clauses filter to create this query SELECT ...
0
votes
1answer
597 views

errno: 150 “Foreign key constraint is incorrectly formed” [closed]

What's my problem with my foreign key reference? This table is not being created? <?php /* ** Plugin Name: *** ** Plugin URI: *** ** Description: *** ** Author: *** ** Version: *** */ class ...
0
votes
0answers
379 views

An SQL query to find orphaned image attachments and their meta

This is for people who are good with MySQL queries. I'm using phpMyAdmin locally to try to optimize an old WordPress & Woocommerce site which has gone through a couple of iterations over the years....
0
votes
1answer
25 views

WordPress database error - quick review

This error appears when I try to activate one option in widget. I broke it in multiple lines so it may be easier to review. I hope it should be very quick to fix code for someone who is familiar with ...
2
votes
1answer
900 views

How to auto login user again after change user_login

I have a system work by ajax that is change user_login of users and this is my code: $wpdb->update($wpdb->users, array('user_login' => sanitize_text_field($args['user_login'])), array('ID' =&...
0
votes
0answers
169 views

Correct and secure way to access a custom SQL database in a custom PHP template file

I am currently developing a WordPress site with Wampserver64 (localhost). I have created a custom SQL database using a custom plugin, wp_my_database, located in the wordpress folder. I can access the ...
0
votes
2answers
6k views

How to delete a particular row in a database table

Here I created a custom profile page based on the current logged user to check only his own data inserted in a custom database. You can see that in every row, I added a button "Delete" missing the ...

1 2 3 4 5 14