Tagged Questions

SQL (Structured Query Language) is a special-purpose programming language designed for managing data held in a relational database management system (RDBMS).

learn more… | top users | synonyms (1)

0
votes
1answer
310 views

How to display data from db in select list [closed]

I wonder what it's wrong in my code. I can't get all of data in column "adres". In result I only have the lest record. Thanks for help. global $wpdb; $result = $wpdb->get_results ("SELECT ...
0
votes
1answer
65 views

Help me SELECT thumbnail from SQL and use

//MySQL Username $user = "myuser"; //MySQL Password $pass = "mypass"; //MySQL Database Name $database = "mydb"; //Number of posts you want to have appear $numOfPosts = 7; //Setup connection $mysqli = ...
0
votes
0answers
58 views

Delete duplicate custom field with specific vaule

I'm trying to delete specific custom fields that have been duplicated, however i only want to delete the fields with the value 0 in them. I currently have this code that will delete the duplicate ...
0
votes
0answers
37 views

problem in sql syntax

problem in Mashable Slider Clone plugin when upload it in server WordPress database error: [You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for ...
0
votes
3answers
112 views

Get a count of how many times a term or a category is used in posts

I need to find out the number of times a term/tag or category is used in a post in WordPress. I wrote the below SQL query. SELECT t.name , count(*)FROM wp_terms t JOIN wp_term_taxonomy tt ON ...
1
vote
0answers
66 views

How to import a Typo3 database to a wordpress site?

I have a SQL database export from a Typo3 site. Does anyone know know or have any experience of dealing with these cases?
0
votes
1answer
291 views

Select column name dynamically mySQL Query

$country="USA"; $dr=$wpdb->get_results("SELECT $country FROM wp_shipping WHERE ID=$ids"); I want the above query in WordPress file, where country name is given dynamically but I am not getting ...
1
vote
0answers
433 views

$wpdb->insert() does not Insert record in a table

I'm trying to understand and get hold of the $wpdb global object but can't seem to make it work. Basically, I'm trying to insert a single record into a custom table in wordpress DB. Instead of ...
0
votes
0answers
67 views

Delete junk text from all the post using my sql command

Because of an autoblog plugin, my site has got junk text in every post! The text format is as below .. funny-pictures/funny-pictures-of-the-day-30-pics/attachment/funny-pictures-41-2/" ...
1
vote
1answer
196 views

Attempt to improve WP search, can someone check my SQL query?

I'm stumped. I've done a bunch of work to filter what posts get pulled in a WP search and then even more work sorting those after they're pulled from the DB. My main problem now is getting results ...
1
vote
1answer
173 views

find pods item where relationship to other pod is not set

I need to fix the effect of an error that left empty a relationship field that should have been autofilled. To fix this I need to find all pods item that has the relationship not set, but I don't ...
0
votes
1answer
115 views

How do I insert a new meta key / value pair, but only if another meta key is present?

I need to add a new meta key and value part only on posts where another key is present (regardless of its value). I tried to use a query to automate it, but my SQL is quite limited Here's what I ...
0
votes
1answer
48 views

Removing links from posts in WordPress

I have few blogs for some clients. I need to remove links to one of my clients blogs in all posts. Just to be clear I need to remove links and my keyword should stay like it is. I found this plugin, ...
0
votes
2answers
398 views

WPDB SQL query with prepare() returning variable, not db value

I have been trying to get this to work for awhile now and I cannot seem to get any farther on my own. It seems to work fine as a normal SQL query but not within the WP framework using prepare(). ...
-1
votes
1answer
2k views

cleaning up safely wordpress wp_postmeta table

In a effort to facilitate maintenance of my site, optimise page loading , and also helping out db migration , i am trying to cleanup the wordpress database of my site. i ahve realised the wp-postmeta ...
0
votes
1answer
741 views

How to remove in the wordpress database all posts revisions except the last three?

here is the commonly recommended sql command for removing posts revisions and cleaning up the wp database: DELETE a,b,c FROM `wp_posts` a LEFT JOIN `wp_term_relationships` b ON (a.ID = b.object_id) ...
0
votes
1answer
200 views

mass delete posts based on metadata

I need to delete all posts that have a certain meta value for a certain meta key. I am looking for how to do this directly in the DB. So for instance, I have a meta field called "state", and I want to ...
0
votes
1answer
92 views

wpdb_prepare with multiple or condition

I want to execute a query like this: $wpdb->prepare( "SELECT * ... from ... WHERE ( post_title LIKE '%%%s%%' or post_content LIKE '%%%s%%' )..., $string ); If I do the query with only one ...
0
votes
1answer
42 views

Extending the database

I'm trying to add an extra column to the comments database which will store the user ID of the post/page author. This is part of a plugin which will display new comments in reply to either a post or ...
0
votes
2answers
222 views

How to use get_results() in widget front end?

I'm trying to get_results() in my widget's front end, this is my current code: public function widget( $args, $instance ) { echo $args['before_widget']; if($children = $wpdb->get_results( ...
0
votes
1answer
90 views

How to concatenate two separate colums into one?

In phpmyadmin I have two separate columns for latitude and longitude. e.g. lat: '38.897683' lng:'-77.03649'. These coordinates are generated for my location custom posts. How can I automatically ...
0
votes
1answer
129 views

query specific posts according their custom fields, using sql SELECT

My posts have a bunch of custom fields, to help insert and display custom info easily. I am trying to build a search that would select and display posts according values of specific 2 custom fields. ...
1
vote
1answer
109 views

posts_where Fails with More than One Custom Field in Query

Querying either of the 2 fields individually gives the expected result (posts are displayed). But, when both fields are included in the query (ex = 'foo' and 'bar' shown in below example), then no ...
1
vote
4answers
229 views

wordpress ajax relationship query

Using the relationship field from Advanced Custom Fields I link artists to events. Both these artist and events are custom post types. For each event, the post IDs of the related artists are stored in ...
0
votes
1answer
264 views

Query sql for truncate post_content in wp_posts table

Hello all i need remove all info in Wordpress posts content and i'ld like do it from phpmyadmin with a query. I need remove only the text and images from all posts content but not the entire post, so ...
0
votes
1answer
57 views

For a complete backup, is it enough to copy htdocs and export database?

I copied the htdocs via FTP from the server which hosts my wordpress blog. Moreover, I used phpMyAdmin to export the MySQL database. When I move to a new server, can I just create a database, run the ...
0
votes
1answer
234 views

When sorting WP_List_Table, table sorts, but I also get SQL errors

Here's my lovely prepare_items() function: function prepare_items() { global $wpdb; $table_name = $wpdb->prefix . 'blah'; $per_page = 100; $columns = $this->get_columns(); ...
0
votes
1answer
156 views

How to export database correctly for local to online

This process as a whole is fine... but I seem to have one small issue when I upload the database online. If I create a theme and modify some options that's fine for the local version. Once I upload ...
3
votes
2answers
239 views

Extending WP_Query — Optimise SQL query

I'm storing posts, a user follows in a custom table that has the columns id, post_id and user_id. To fetch posts that a user follows I have extended the WP_Query as follows: class ...
0
votes
1answer
41 views

Wordpress SQL - How to Check for Category?

I'm using the following SQL (wrapped in php) to find posts in a wordpress database: $sql = " SELECT p.* FROM {$wpdb->prefix}most_popular mp INNER JOIN ...
0
votes
1answer
127 views

SQL Query in WordPress - Getting Impossible WHERE error

I don't get any result in the SQL query below. I am trying to find user_id of users with custom usermeta fields. SELECT DISTINCT user_id FROM wp_usermeta WHERE ( ( ...
0
votes
0answers
49 views

Getting deleted users in database

I am using the database that is being used by a WordPress site. I am trying to get all the users from wp_users table with SQL query. But there is also previously deleted users in wp_users table. I ...
0
votes
2answers
2k views

Getting value from database table depending on field value

I am using a plugin called formidable which is similar to Gravity Forms in terms of purpose. I have two fields of interest. The first field loads up all the values in the Town column of my ...
0
votes
2answers
72 views

How can I order metaboxes in my posts in WordPress?

hello i did add a custem filed and this is my code add_action( 'add_meta_boxes', 'cd_meta_box_add' ); function cd_meta_box_add() { add_meta_box( 'my-meta-box-id', 'المعلومات الرئيسية لفلل مشروع', ...
-1
votes
1answer
228 views

SQL query to check whether a meta key is set or not for a post in post_meta table

Condition: some post have meta_key 'status'. Please help me in with this condition: sql query for those post who don't have meta_key 'status'
0
votes
1answer
246 views

SQL: Select wordpress posts with given text string and add a custom field to them?

I want to select all wordpress posts that have a certain text string. Then to add a custom field to all those posts. Here is what I figured out so far but it doesn't work INSERT INTO wp_postmeta ...
0
votes
1answer
106 views

An action hook where a comment meta is updated

By analogy to the hook on post meta update, I use the following code for hooking when comment meta value is updated. My comment meta key is "consider" and can have 2 values: 0 and 1. My Goal is to ...
0
votes
2answers
145 views

count number of user comments with a specific comment meta value

I am using the code below to count the number of comments by a certain user: global $wpdb; $count = $wpdb->get_var( 'SELECT COUNT( comment_id ) FROM '. $wpdb->comments .' ...
1
vote
1answer
3k views

Using OR conditions in meta_query for query_posts argument

I have searched high and low for this but I cant seem to locate anything. I am trying to filter some results and when I make an args array like this and pass it to query_posts I noticed that the ...
0
votes
2answers
121 views

Which query method to use? (edit- wpdb syntax problems)

I am trying to create a query in order to get all the metadata from a custom post type named match_reports that is associated with a meta_key and meta_value in another custom post type named ...
0
votes
1answer
420 views

SQL Query to select post title & post ID from a particular category

I am looking for SQL query to select post title & post ID from a particular category. I looked at wordpress table structure but it is really confusing me.
0
votes
1answer
89 views

Custom Wordpress SQL Query 4 posts per custom taxonomy

I'm currently developing a Wordpress website that has a large navigation that lists the 4 most recent posts within a hierarchical taxonomy. I dont have any experience with $wpdb, but it seems like ...
0
votes
1answer
61 views

count number of all comments by a user on different (non-repeated) posts

I thank you in advance for your help. I am using Wordpress for about 2 years, but always avoiding SQL inside my scripts and looking for built-in functions to perform my goals. To count the comments ...
0
votes
0answers
87 views

Ranking authors by post meta value

I have custom post-type with custom post-meta and i want to rank authors by post meta value.I can show the SUM of a meta value on author page with this code <? php $points = ...
1
vote
2answers
590 views

Optional Meta Query

I have places stored as posts in WP's posts table. I am doing some geo-locating using Geo Data Store (http://wordpress.org/plugins/geo-data-store/). This is working great for me, as I can currently ...
0
votes
1answer
575 views

WP_Query with several meta_query-statements and order by meta_value

This is my query: $the_query = new WP_Query( array ( 'post_type' => 'pass', 'posts_per_page' => '-1', 'post_status' => 'publish', ...
0
votes
1answer
169 views

wpdb prepare sql problem

I have problem with wpdb prepare and sql query. If i run the query directly thru wpdb->get_results it's working fine. Here it is: $alabala_sql = $wpdb->prepare( " SELECT * FROM ...
0
votes
2answers
123 views

making php value numeric

I used some of this code from this page on Stack Overflow: Using wp_query is it possible to orderby taxonomy? It's about the function to be able to sort a query by a taxonomy value. Although it works ...
0
votes
2answers
808 views

Up/Down voting system for Wordpress

Looking in all posts with keywords "voting system, upvote, downvote", I can't find a satisfying solution for this issue, except accepting one of the available plugins, spend a lot of time undersanding ...
0
votes
1answer
282 views

SQL Bulk Move old posts by one author to another category

I'm looking to move a number of old posts by one author from one category to another category and was hoping someone could help me do this? I figure the easiest way would be through an SQL command? ...