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

How to pull data from custom forms to .xls format from specific table and column [closed]

Any easy method to pull out specific date from particular column from sql data to .xls format
0 votes
1 answer
73 views

SQL Query to get post_id from wp_posts and and meta_key(s) from wp_postmeta

I have a custom post type called media_coverage and need to export via PHPMyAdmin some of the data in that post type that is in wp_posts (post_title) and also in associated wp_postmeta (meta_key) keys....
0 votes
0 answers
35 views

Search results always returns "No results" no matter what

pre_get_posts hook that never works I used the following code both in functions.php of my theme and in my custom plugin in the "after_theme_setup" hook (pre_get_post code only as it is alot ...
0 votes
2 answers
39 views

How to use orderby on meta_value when using Pods custom database table storage

I'm struggling to understand how I can use pre_get_post when the post's metadata is not stored in the wp_postmeta table. I use Pods (https://pods.io) to create custom post types with custom fields, ...
0 votes
0 answers
14 views

Adding CASE in WP_Query

How can we write this query using WP_Query select wp_posts.ID , wp_posts.post_title, wp_postmeta.meta_key, ( CASE WHEN wp_postmeta.meta_key = '_end_date' THEN wp_postmeta....
  • 1,226
0 votes
1 answer
17 views

WP_Query: How to get results from both meta_key options?

I have the following WP Query: if(isset($_GET['scope']) && !empty($_GET['scope'])) { $scope = $_GET['scope']; } else { $scope = ''; } $foo = new WP_Query([ 'post_type' => '...
0 votes
0 answers
20 views

how to delete in phpmyadmin sql - all users with certain condition and all dependencies

I have in my wordpress website a bunch of pages that has mydomain.com/author/gertielamrertyk/ can someone help me create an sql that will delete all users with certain condition (in my case it is a ...
  • 61
0 votes
1 answer
18 views

Wordpress can I manually add columns in users table and display it in the default manage user plugin and registration form? [closed]

How would I go about doing this? Thank you!
  • 1
0 votes
1 answer
31 views

dynamic page using php from sql database

The Problem I am really struggling to get wordpress to generate a page dynamically based on the content of a database. The Context I have a sql database which contains unique slugs and Ids, and I am ...
0 votes
0 answers
14 views

Sql query does not work well

I have a problem with a SQL query in wordpress. I create a query that return product_ID of products that have one or more attribute. I have highlighted my problem. I want to displya the product that ...
1 vote
0 answers
18 views

WordPress is not creating table in database after activating plugin,

I struggled with this a long time! Can anyone help me? My plugin is not creating a database table once activated. The following code is in the main plugin file. function woocq_activate() { global ...
  • 11
0 votes
1 answer
35 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 ...
0 votes
0 answers
151 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 ...
  • 31
0 votes
1 answer
30 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 ...
0 votes
1 answer
154 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 ...
  • 111
0 votes
0 answers
27 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' =...
  • 3
-1 votes
1 answer
67 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->...
0 votes
1 answer
33 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: $...
  • 113
0 votes
2 answers
64 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 ...
  • 111
0 votes
0 answers
17 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 ...
  • 1
0 votes
0 answers
31 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){ $...
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 ...
0 votes
0 answers
39 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( ...
  • 146
0 votes
0 answers
40 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 ...
0 votes
0 answers
40 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 ...
0 votes
0 answers
49 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 ...
0 votes
0 answers
24 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 ...
  • 230
0 votes
0 answers
20 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 ...
  • 230
0 votes
0 answers
103 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 ...
  • 397
1 vote
0 answers
45 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') ...
1 vote
1 answer
54 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 ...
1 vote
0 answers
53 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. ...
0 votes
0 answers
18 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 ...
  • 152
0 votes
0 answers
97 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?
0 votes
0 answers
48 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 ...
  • 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 ...
0 votes
0 answers
22 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 ...
1 vote
1 answer
60 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 ...
  • 152
0 votes
0 answers
13 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 ...
  • 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, ...
0 votes
0 answers
12 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 ...
0 votes
0 answers
34 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 ...
0 votes
0 answers
20 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 ...
  • 1
0 votes
0 answers
27 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 ...
0 votes
1 answer
39 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(" ...
0 votes
0 answers
18 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 ...
0 votes
1 answer
183 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....
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: ...
  • 1
0 votes
0 answers
59 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 ...
  • 1
0 votes
0 answers
103 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 ...
  • 11

1
2 3 4 5
16