Skip to main content

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

Sql formatting for post data within function

I'm calling a function through ajax in my site, and within the function that's being hit I'm taking the data (in this case it's a search term) and putting it into LIKE statements in sql: $...
Geoff_S's user avatar
  • 123
0 votes
2 answers
576 views

Wordpress SQL LIKE request doesn't work for fields with special symbols

In WordPress I make SQL-requests to the database but LIKE request doesn't work correctly. Actial value of meta_value field in the database is such string: a:1:{i:0;s:9:"full-time";} if I ...
Kir Mazur's user avatar
  • 111
0 votes
0 answers
33 views

This code is supposed to only allow user to be authenticated if accountVerified is equal to 1, but it still allows user to be authenticated otherwise

global $user_id; global $wpdb; if(is_user_logged_in()){ header("Location:https://www.recovermenow.co.uk"); } if(!$user_id){ if($_POST){ $...
Sheran Malik's user avatar
0 votes
0 answers
33 views

Why is my insert row only inserting the final row from the loop into the database rather than just inserting one

<?php session_start(); if(is_user_logged_in()) { global $wpdb; $id = get_current_user_id(); $recoveryID = null; // $results = $wpdb->get_results('SELECT * FROM ...
Sheran Malik's user avatar
0 votes
0 answers
215 views

Unknown column 'wp_posts.ID' in 'field list

I'm getting WordPress database error: [Unknown column 'wp_posts.ID' in 'field list'], but column does exist, can someone please tell me what I'm doing wrong? SELECT * FROM wp_posts WHERE ID IN( ...
Darko's user avatar
  • 146
0 votes
0 answers
141 views

Counting Posts with multiple taxonomy and terms condition using MySQL and AJAX

I am trying to get the number of posts with multiple taxonomy and terms using MySQL and AJAX. but I cannot get the desired result with my query. I derived my query in this wpdb query and sadly it ...
Blitzkriegfest's user avatar
0 votes
0 answers
65 views

Change pure SQL database query to WordPress post query?

I am trying to query posts that are nearby a given (lat/long) location. I have found this working SQL query, but this won't provide me flexibility to alter the queried later on, since I am not really ...
RobbTe's user avatar
  • 242
0 votes
0 answers
208 views

Database SQL query error

I am trying to run below query. $sql = "SELECT * FROM `wp_podsrel` WHERE `related_item_id` =$user->ID AND `pod_id` = 17 AND `field_id` = 25"; $results = $wpdb->get_results($sql) or ...
Foysal's user avatar
  • 449
1 vote
0 answers
350 views

Sorting events by descending date, and ascending time if multiple events on a date

UPDATE: Solved with the answer below. $past_events = array(); $past_events_sql = $wpdb->get_results( $wpdb->prepare( "SELECT p.ID, from_unixtime(m.meta_value,'%%Y-%%m-%%d') ...
Jen Abella's user avatar
1 vote
1 answer
312 views

How To Fix WP Query Returns Results But Shouldn't?

I have a WP Query that should return no results, but instead seems to be returning items. I'm guessing the null result is being interpreted as "return all results" but I'm not sure the ...
opendatum's user avatar
1 vote
0 answers
125 views

How to change post published date to today date with SQL

How to change already published post date and time to current date and time using SQL. I have a solution for the year but I don't know how to change the whole date to the current date and time. UPDATE ...
Puneet's user avatar
  • 47
0 votes
0 answers
249 views

Bulk delete WordPress Post and all metadata, etc using SQL query

Is it still possible to bulk delete WordPress post and it's meta data, etc using an SQL query, I tried using some queries from years ago but didn't work. How can I do this?
overdeveloping's user avatar
0 votes
0 answers
82 views

SQL command to delete "pending comments" doesn't work...?

This is the SQL command: DELETE FROM wp_comments WHERE comment_approved = 0 This, as you can see in the screenshot below, says that the operation was executed ok but no rows affected....which is odd ...
Henry's user avatar
  • 983
1 vote
1 answer
420 views

WP Optimization: Removing Orphaned wp_options (especially the autoload ones)

Is there no mechanism which purges old options from the DB? I tried a few plugins in the past and I found out that there are a few pretty long option strings which are set to autoload but IMHO not ...
tim's user avatar
  • 164
0 votes
1 answer
191 views

Why line returns are not reapply after doing esc_sql?

I trying show data from my database. This data was escape by esc_sql like bellow. But when I use it in echo, line-returns are print as normal chars ('\', 'r', '\', 'n'). $data = esc_sql(" ...
Adrien Villalonga's user avatar
0 votes
0 answers
21 views

How to set wordpress url on local host to access it via VPN

I have an issue. I have wordpress installed on raspberry PI that is connected to my home local network. I have a conenction to this pi via hamachi VPN. The issue is that in SQL database there is url ...
user164948's user avatar
1 vote
1 answer
731 views

Build A Custom SQL Query for WordPress Search

I was working on a code, where I used SQL to find something on my site. I realised that the SQL was giving me far accurate search results, and wanted to implement the same in my WordPress search query....
Aditya Agarwal's user avatar
0 votes
1 answer
22 views

Getting rid of unwanted nonSQL syntax characters when debugging a query

I am trying to debug a SQL query, but I am getting a lot of @r and other unwanted characters right before I run the query like so: print_r($query); die; $rows = $wpdb->get_results($query); I get: ...
Sayaman's user avatar
  • 135
0 votes
0 answers
227 views

Menu Order updating automatically

I have a custom post type with page-attributes declared so I am able to put in a menu_order number/field for sorting them via menu order. This all works as expected except this next issue. I reset all ...
gishua's user avatar
  • 11
0 votes
1 answer
93 views

Storing huge number of users in wordpress

I would begin coding a school management theme project soon and am looking to keep the DB neatly organised. In this pursuit, since the students could be thousands in a school, would it be a good ...
Raging Vids's user avatar
0 votes
0 answers
58 views

Custom SQL query slows down when using multiple OR ... LIKE ... in posts_where filter

I have built a posts query that includes a custom table in search using the posts_join and posts_where filters. Now the customer wants me to include yet another custom table in the search, but doing ...
gl03's user avatar
  • 111
0 votes
1 answer
56 views

add role on WordPress in PHP on a second database

I have a site A (a store) where once the purchase is made the new user has to register in site B (a members area). To do this I connected the second database and also managed to pass the various info ...
Matteo Feduzi's user avatar
0 votes
1 answer
2k views

WooCommerce database query : Get product category image path+name from thumbnail_id [closed]

I am trying to list all my Woocommerce Product Categories | category name | category slug | ... | ... | category image path+name | Using this query below, gets me most of the way: SELECT * FROM ...
TaoRich's user avatar
  • 121
0 votes
0 answers
129 views

DB prefix not updating

I have a site I built locally and migrated to a live environment. Later I created a copy of this site and booted it up locally again to do some further dev in there. My local dev software (Local by ...
mtm's user avatar
  • 43
0 votes
1 answer
162 views

Trying to create a shortcode to display categories with a specific product tag

I currently have the following and it is not working: If I put the shortcode [tagtagtag=246] i get an array to string error function get_categories_with_product_in_tag( $atts ) { $atts = ...
challenge2022's user avatar
1 vote
1 answer
3k views

SELECT custom post type and its meta in SQL

So I have the following SQL script where I can view all my post_meta with specific meta_keys: SELECT * FROM `wp_postmeta` WHERE `meta_key` = 'honorific' OR `meta_key` = 'suffix' OR `meta_key` = '...
Sem313's user avatar
  • 13
0 votes
0 answers
135 views

SQL DELETE multiple post_meta on single and multi-sites

So I don't have too much knowledge on SQL and running scripts, so I wanted to see if the community can help me. Here is what I'm attempting to do: Delete all post_meta that has the meta_keys honorific,...
Sem313's user avatar
  • 13
1 vote
0 answers
206 views

Bulk-create posts from SQL database

I'm new in this forum and fairly new to Wordpress as a whole, so I hope I will abide by all written and unwritten rules when posting this. I have an SQL database with around 4,000 posts from an old ...
Ran_Char's user avatar
0 votes
1 answer
194 views

WP_Query() not working as expected

I'm building a plugin for EDD which adds a custom metabox with checkbox option meta_key _xy_global_product. So far, so good. In the frontend, I'm trying to filter posts which have this meta_key set to ...
Daan van den Bergh's user avatar
0 votes
0 answers
371 views

Deleting empty meta key values

Is it safe to use DELETE FROM wp_postmeta WHERE `meta_value` = '' in SQL in order to remove meta keys with empty values? Could any errors or problems occur?
frankus's user avatar
0 votes
0 answers
76 views

Fetch Data from an external MSSQL Database in a Managed WP hosting

SO, my client is using a managed WP hosting, which is why I can't install MSSQL drivers in his server. I am building a plugin for him to fetch some data from their office's MSSQL server. Now, I have ...
shafee ul kabir Fahim's user avatar
0 votes
1 answer
565 views

How I can change the condition or compare operator for WP_Query in pre_get_posts

So here is my problem I want to show Posts if have same category if not have post then show post of same tag. And to do that I am using "pre_get_posts" action. and setting query like ...
Nilesh Chouhan's user avatar
0 votes
2 answers
454 views

Increment integer field in database when WHERE needs to be dynamic [closed]

I have a database column called "upvotes". I have another column called "userid". I would like to increment the value in the "updates" column where the userid matches the ...
user44109's user avatar
0 votes
2 answers
531 views

Do I need to sanitize $_POST['keyword'] before send to 's' parameter?

Anyone know how to sanitize the $_POST for wordpress? $args = array( 's' => esc_attr( $_POST['keyword'] ), );
user205932's user avatar
0 votes
0 answers
35 views

Cannot get sql request from Query object?

$qry = new WP_Query(array( 'post_type' => $this->type, 'posts_per_page' => -1, 'meta_query' => array( array( 'key' => "_{$this->metaPrefix}...
Sayaman's user avatar
  • 135
0 votes
1 answer
24 views

add products to WordPress site automatically

i have a products sql database table from none WordPress old site with names description and category fields but the category has only id from category table and i have to move all these products and ...
sonia's user avatar
  • 1
0 votes
0 answers
664 views

How to get image path from id using SQL

I want to use a SQL query to get some random users and display an advanced custom fields profile image. Currently with this query I get the image ID back but I somehow from that need to get the url ...
Waterfall's user avatar
  • 105
0 votes
1 answer
52 views

I want to get on those users their meta value are like "AGENT" .. but this query is not working

SELECT display_name FROM $wpdb->users WHERE id IN (SELECT user_id from $wpdb->usermeta where meta_value LIKE '%agent%')
Sam's user avatar
  • 1
0 votes
0 answers
41 views

Customising the default wordpress search functionality

I find the current from WordPress too strict as it doesn't allow for some minor spelling mistakes. How can I edit this function? I was checking out pre-get-posts however I don't think that allows me ...
MrDigitalis's user avatar
1 vote
0 answers
59 views

Editing the default wordpress search

My wordpress sites search function is not relaxed enough for my liking. I want it to match more items and be less strict. How would i do this? I was thinking it would to do a pre-get posts filter but ...
imJustAskingMan's user avatar
1 vote
2 answers
64 views

Difficulty importing my live site to local

Im using local by flywheel, Here are the steps i have taken so far: Installed local by flywheel and created a site called stage Downloaded the website from CPanel and also the SQL database Imported ...
iheartex's user avatar
0 votes
1 answer
1k views

wpdb->get_row is selecting the variable as a column name

I'm using wpdb to get a row of a table $file = $wpdb->get_row( "SELECT * FROM {$wpdb->prefix}vip_files WHERE {$file_hash} = `hashcode`&...
Mohammad Afzali's user avatar
0 votes
1 answer
50 views

Run a sql (update) after 12 hours after the user login. Woocommerce users

How can I Run a sql (update) after 12 hours after the user login (for Woocommerce users) After 12 hours after a user login, I want to run a sql/ function to update a value in the database. To set a ...
Nabil Dabbagh's user avatar
0 votes
2 answers
1k views

Display data from phpMyAdmin with WordPress

I have imported my website to Wordpress and facing a big issue how can I do sql Query to display data on my pages with wordpress? for example I have product, price, description which I need to display ...
Martin's user avatar
  • 1
0 votes
0 answers
169 views

How delete post_content records of specific category from phpmyadmin

I need a SQL command to delete post_content records for specific category's posts
akhbarejadid's user avatar
0 votes
1 answer
655 views

SQL Bulk update all Wordpress user's nicknames to firstname + lastname format

I'm trying to bulk update all my users on one of my Wordpress sites to so that their nicknames aren't the default username but have the format firstname + lastname instead. I've put together this code ...
jamesmonk83's user avatar
1 vote
0 answers
814 views

Sql query to get all metadata for a post

I have three tables in my database one is users table the other is posts and wp_post meta. In the user table I have all the user details . In the wp_posts table I have different posts types . I want ...
technical Zillancer's user avatar
0 votes
1 answer
711 views

How to get database connection details without longing to cpanel in WordPress?

I am creating a WordPress plugin and in my plugin i need to do some SQL statements ,in the site i am working on i have access to WP-admin but i cant get to the files to get database name and password ...
anna's user avatar
  • 9
0 votes
2 answers
78 views

Which data is written and stored in the database when read-only (non-posting, non-commenting) users visit the site?

With a default Wordpress install, with no plugin installed, does the read-only visiting of the website generates write operations in the database? By read-only, I mean: visitors come and don't post ...
Basj's user avatar
  • 85
1 vote
3 answers
1k views

Syntax for $wpdb->prepare when searching in two columns

I have this working statement for searching a single column in my database: $foods = $wpdb->get_results( $wpdb->prepare( "SELECT id, foodname, namevariations, calories, carbs, fat, protein, ...
Andy Bay's user avatar

1
2
3 4 5
17