Quantcast
Browsing all 44 articles
Browse latest View live

WPDB SQL Ignore `post_status` Parameter

I use this SQL statement: SELECT * FROM wp_posts LEFT JOIN wp_term_relationships ON ( wp_posts.ID = wp_term_relationships.object_id ) LEFT JOIN wp_term_taxonomy ON (...

View Article


Plugin with connection to database – Single function

I’m creating a personal plugin with more files and I need to connect to an external database with WPDB. At the moment I’m repeating “new wpdb(…)” in every function, in every file, of my plugin. Is...

View Article


wpdb and acf via wp rest api

I made a custom endpoint with wp rest api for /wp-json/dn/locations which in turn runs the following wpdb query $sql = "SELECT * FROM wp_posts p WHERE p.post_type = 'location' AND p.ID = 133;";...

View Article

Is it mandatory to use $wpdb->prefix in custom tables

Sorry if this question is trivial. I’m just beginning to develop plugins in WordPress. In all the tutorials I found this: while creating the custom tables, $wpdb->prefix is used. Example:...

View Article

WordPress get pagination on wpdb get_results

How do I gee the numbered pagination of custom wpdb result? below code will show one latest post from each authors in the site. I want to show 20 posts per page with a numbered pagination. $postids =...

View Article


$wpdb returns duplicate posts

I have created a shortcode which shows the posts which were created after the user last logged in. The shortcode is working perfectly fine, but I am not sure why but I am getting 7 duplicate posts. So...

View Article

duplicate entries in database while using save_post or wp_insert_post

Here is what I am trying to do – I have created a custom table in the database and I am trying to enter data into it everytime a post is created. The database-entry needs to happen ONCE AND ONLY WHEN A...

View Article

Quotes in table name

Since WP3.5, prepare() accepts placeholders as a security measure, instead of just appending the argument to the query. Therefore, $wpdb->prefix needs to become a second parameter, called by %s:...

View Article


I am getting allowed memory exhausted in wp-db.php

Today I checked my error_log and found these errors in it. PHP Fatal error: Allowed memory size of 176160768 bytes exhausted (tried to allocate 5290845 bytes) in...

View Article


Image may be NSFW.
Clik here to view.

wpdb giving different results then query in SQL Editor

I’m trying to read candidates and the relation with expertises from 2 custom tables in my WP Database. This is my WPDB query : $candidates = $wpdb->get_results(" SELECT * FROM wp_bullhorn_candidates...

View Article

Updating with $qpdb->query() always returns 0 rows affected

I’m experiencing an odd situation while running an UPDATE with $wpdb->query(). Given the users table, with columns user_id (Primary Key) and status, and the user 3 existing and with status 0, I run...

View Article

$wpdb->get_results returns NULL

$qry = 'select * from wp_wcmanage_9999 where order_updated IS NULL'; $get_orders_data = $wpdb->get_results($qry, ARRAY_A); var_dump($get_orders_data);// Returns NULL When i am executing same query...

View Article

$wpdb how can i save my postmeta table before querying it

This function is in my functions.php file. The query returns the value I’m looking for via phpmyadmin, but only AFTER the function has been run in WordPress. add_action( 'transition_post_status',...

View Article


Site going down due to slow queries

My site keeps going down and the host says it’s due to some slow queries overloading the server. They’ve supplied a list of slow queries, any pointers as to what I should be doing to get rid of or...

View Article

Passed variable gets undefined variable error on insert on next page

I am passing a variable with $_POST to another page and on the destination page I want to perform an insert operation and want to use that passed value . The variable “$mygroup” is coming from a forms...

View Article


Image may be NSFW.
Clik here to view.

Getting users who registered 360 days from current date

As per the title, what I want to do is run a custom query that (using WP-Cron) will run once a day to check for users who registered exactly 360 days before the current date (don’t need time, just...

View Article

Does WP query update accept variables being built into it?

Trying to figure out if this is a WP specific quirk. The var_dump code shows the correct string to be inserted but the last query dump at the end shows an incomplete query with no variable being passed...

View Article


Get number of comments after modifying comment query

I have modified the comment query arguments in comment-template.php from $author_id = get_query_var( 'author_id', 1 ); $comment_args = array( 'order' => 'ASC', 'orderby' => 'comment_date_gmt',...

View Article

Inserting Post Meta From SQL

I’m trying to get post meta to be updated/replaced with $wpdb and running into issues. I have working SQL, but cannot get it work when coding it up for my WP plugin. Extra note: The post meta being...

View Article

How to get top 10 user is based on user meta value

I’m trying to get top 10 users in my wordpress blog based on user meta value. I’ve tried few methods & finally able to get just top one user using below wpdb query. But clueless, how we can get top...

View Article
Browsing all 44 articles
Browse latest View live