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
5 views

custom tables in wordpress Database? (can i just create them with sql?)

i just want to create a custom Table in my WordPress database and i saw many php functions to deal with that my question now is : can i just create them with an sql command and for what do i need to ...
user avatar
0 votes
0 answers
12 views

How to bulk remove post media "open in new tab" behaviour

In my wordpress posts, some images are clickable and some are not. When they are clicked, they open a new page. I do not want any clicking & url behaviour. This is the behaviour I am referring to: ...
user avatar
  • 13
0 votes
0 answers
80 views

SQL query - get a featured image's alt / alternative text

I am writing some SQL queries to get post data out of a database for certain posts (so WP functions are not an option). I am trying to get post IDs, post URLs, post featured image URLs and associated ...
user avatar
  • 31
0 votes
0 answers
21 views

REGEXP_REPLACE in post_contet

So, basically, I want to remove trailing slashes from specific domain urls. For example: https://www.example.com/here/postname/ into https://www.example.com/here/postname I have 10.4.21-MariaDB which ...
user avatar
0 votes
1 answer
18 views

How to left join meta in queries [closed]

I have a query something like //read products with thumbnail and sku SELECT products.*, pm1.meta_value as sku, p1.guid as thumbnail FROM `wp_posts` as products LEFT JOIN `wp_postmeta` as pm1 ...
user avatar
  • 111
0 votes
0 answers
23 views

get_terms with specific id order

I have the specific query $queried_object = get_queried_object(); $taxonomy = $queried_object->taxonomy; $term_id = $queried_object->term_id; $isActive = 0; $postTerms = get_terms( [ 'taxonomy' =...
user avatar
  • 3
-1 votes
1 answer
27 views

wpdb prepare without placeholder

Recently, I found out why there are a lot of PHP Notice on my debug.log. It is because of wpdb:prepare needing placeholders. Documentation says that I need to do: $wpdb->get_results( $wpdb->...
user avatar
0 votes
1 answer
31 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: $...
user avatar
  • 113
0 votes
2 answers
46 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 ...
user avatar
  • 111
0 votes
0 answers
15 views

JOIN and SUM different statement results (Mailster Database)

After the last update of Mailster (email marketing plugin for wordpress), they have changed the way they store the information about opens, clicks, unsubscribes... Until now, everything was stored in ...
user avatar
  • 1
0 votes
0 answers
30 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){ $...
user avatar
0 votes
0 answers
28 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 ...
user avatar
0 votes
0 answers
24 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( ...
user avatar
  • 146
0 votes
0 answers
21 views

SQL query injection with fifu image

I am using featured image url plugin on my web site. due to some customization of my new wp theme I want to set my featured images to the post content , not to default wp featured images as i checked ...
user avatar
0 votes
0 answers
17 views

How to get specific column data conditionally in database in Wordpress?

I have unique request_id and similar item_id columns in database. Therefore, the same item_id can be stored more than once. I'm trying to get the request_id of the last item_id I specified among the ...
user avatar
0 votes
0 answers
41 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 ...
user avatar
0 votes
0 answers
20 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 ...
user avatar
  • 230
0 votes
0 answers
18 views

Change SQL get_results to search for posts with custom term in custom taxonomy

I am using a SQL database query to get posts that are nearby a given location. I also extended this script so that people can search for posts with a certain name. Now I would like to extent it so ...
user avatar
  • 230
0 votes
0 answers
93 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 ...
user avatar
  • 377
1 vote
0 answers
36 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') ...
user avatar
1 vote
1 answer
41 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 ...
user avatar
0 votes
0 answers
34 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 completion date to the current date and time. ...
user avatar
0 votes
0 answers
17 views

Memcaching recurring SQL Queries

I have a highly dynamic Buddypress page with integrated WPML translation. Right now I'm optimizing a lot of things and using "Query Monitor", I found out, that there are about ~50 Queries on ...
user avatar
  • 152
0 votes
0 answers
40 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?
user avatar
0 votes
0 answers
39 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 ...
user avatar
  • 985
0 votes
0 answers
13 views

Change word in woocommerce product category custom field

I have woocommerce shop with a large number of categories that have a filled custom field "custom_title". Each custom field has the word "Category" and I want to replace it with ...
user avatar
0 votes
0 answers
16 views

Change published date and time using SQL query for page in every 5 hour

If I want to modify publish date and time every 5 hours every day and before modifying the date I also want that for 1 second that post should be drafted then in the next second publish the particular ...
user avatar
1 vote
1 answer
27 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 ...
user avatar
  • 152
0 votes
0 answers
10 views

WP Optimization: Overwriting options to autoload=yes for often used options?

I'm currently trying to optimize my WP-page. I checked with "Query Monitor" and I see a lot of options which are fetched on every pageload (not a huge runtime cumulated, but still ~15-20 ...
user avatar
  • 152
0 votes
0 answers
28 views

get different meta-data of a complicated query at the same time

I have a function that generate a very complicated query with meta_query, tax_query etc. and now am using it in a filter page. i need to fill the filter page by some meta data, like number of paied, ...
user avatar
0 votes
0 answers
11 views

Data is not constatntly loading from custom wordpress table

global $wpdb; $tablename_temp = $wpdb->prefix . 'faculty_temp'; $toke = $_GET['token']; $user = $wpdb->get_results("SELECT * FROM $tablename_temp where token='$toke'"); This is to ...
user avatar
0 votes
0 answers
32 views

Wordpress SQL Prepare

i'm trying to adapt this code to also take in to account specific categories and custom post types, so it would give me select dropdown populated with unique custom field values, from a specific post ...
user avatar
0 votes
0 answers
16 views

Accidently changed the GUID

I accidently executed: UPDATE yemnc_posts SET guid = REPLACE(post_content, 'domainA', 'domainB'); instead of UPDATE yemnc_posts SET guid = REPLACE(guid, 'domainA', 'domainB'); How can I undo this? Is ...
user avatar
  • 1
0 votes
0 answers
25 views

Passing a SQL query to the WP Query

I'm writing this filter and would like your help in fixing the following this code. I will like to take the SQL statement below and place it in a WP query. select post_id from wp_postmeta WHERE ...
user avatar
0 votes
1 answer
29 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(" ...
user avatar
0 votes
0 answers
17 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 ...
user avatar
0 votes
1 answer
105 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....
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: ...
user avatar
  • 1
0 votes
0 answers
36 views

How to run complex query using PHP

I have a rather long and complicated SQL query. I want to use commands like SET @varible, GROUP_CONCAT, PREPARE, EXECUTE, DEALLOCATE PREPARE, case when, etc. I need this data from the DB to construct ...
user avatar
  • 1
0 votes
0 answers
60 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 ...
user avatar
  • 11
0 votes
1 answer
31 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 ...
user avatar
0 votes
0 answers
28 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 ...
user avatar
  • 101
0 votes
1 answer
27 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 ...
user avatar
0 votes
1 answer
265 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 ...
user avatar
  • 11
0 votes
0 answers
58 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 ...
user avatar
  • 29
0 votes
1 answer
50 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 = ...
user avatar
0 votes
1 answer
290 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` = '...
user avatar
  • 3
0 votes
0 answers
53 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,...
user avatar
  • 3
1 vote
0 answers
45 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 ...
user avatar
0 votes
1 answer
32 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 ...
user avatar

1
2 3 4 5
16