Articles of wpdb

Unknown column 'siteurl' in 'where clause' WPDB outside

I am trying to get Mysql values from outside wp. My code: define( ‘BLOCK_LOAD’, true ); require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-config.php’ ); require_once( $_SERVER[‘DOCUMENT_ROOT’] . ‘/wp-includes/wp-db.php’ ); $wpdb = new wpdb( DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); $wpdb->get_var(“SELECT option_value FROM wp_options WHERE option_name = siteurl”); What i missed ?

Incorrect Use of wpdb::prepare()

Not sure what I am doing wrong here. I did not write this code however I am receiving the following error in WordPress: The query argument of wpdb::prepare() must have a placeholder. This message was added in version 3.9. <?php echo ‘<div class=”client_list”><input type=”checkbox” name=”check_all” value=”0″ class=”” id=”check_all” /> Check All</div>’; $send_message_lists = get_post_meta($post->ID, wpvbxcon::smslist_smsclient, […]

Get results from wordpress data custom table

Firstly i created a custom table into the wpdb : global $wpdb; $table_name = $wpdb->prefix . ‘countdown_table’; $sql = ‘ `id` int(11) NOT NULL AUTO_INCREMENT, `styleName` varchar(255) NOT NULL, `css` blob NOT NULL, `expiration` blob NOT NULL, `created` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`id`) ‘; require_once( ABSPATH . ‘wp-admin/includes/upgrade.php’ ); dbDelta( $sql ); […]

$wpdb->get_var multiple queries in one database check

I am using the $wpdb->get_var php code to get the first name and last name on the records, in the wp_usermeta table… But because the field value is stored in the same cell, I don’t know how to merge it into one string. Right now I do it like this: $_EmployeeFName = $wpdb->get_var( $wpdb->prepare(“SELECT `meta_value` […]

WPDB Table Does Not Exist

From this code: global $wpdb; $sidebar_table = $wpdb->prefix . ‘w3care_sidebar_position’; $checkad = $wpdb->get_results( $wpdb->prepare( “SELECT ad_id, sidebar_position, ad_type FROM `%s` WHERE page_id = ‘11646’ AND page_type=’page'”,$sidebar_table )); I’m getting the following error: WordPress database error Table ‘wp_rainnews.’wp_w3care_sidebar_position” doesn’t exist for query SELECT ad_id, sidebar_position, ad_type FROM `’wp_w3care_sidebar_position’` WHERE page_id = ‘11646’ AND page_type=’page’ /* From […]

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 ( wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id ) WHERE wp_posts.post_type = ‘post’ AND wp_posts.post_status = ‘publish’ AND wp_posts.post_status != ‘draft’ AND wp_term_taxonomy.term_id = 17 OR wp_term_taxonomy.term_id = 18 OR wp_term_taxonomy.term_id = 19 ORDER BY post_date_gmt DESC […]

Run posts_where and posts_join only on the main query

Using the pre_get_posts hook, I’m able to take $query as an argument. But on posts_where and posts_join hook, I receive the respective clauses and not the query. The problem is that the hook is running on every query, not just the main one. Given the following code, the code will be executed once on each […]

Using wpdb without loading all plug-ins via wp-load.php

I’m trying to prevent WP from loading all plug-ins when including wp-load.php, since I don’t really need them nor the usual WP actions/filters. All I need is the WPDB class to query the database easily. I’ve only found an (old) solution that involves defining WP_INSTALLING to trick WP into not loading plug-ins, but I’m not […]

How to Generate a list of Most Commented post?

I’m trying to call a list of most commented post. But the call to the DB returns always the same post (the first one in the loop) This is my code in functions.php function lugaresincreibles_most_commented() { global $wpdb; $pop = $wpdb->get_results(“SELECT * FROM {$wpdb->prefix}posts WHERE post_type=’post’ AND post_status=’publish’ ORDER BY comment_count DESC LIMIT 3”); foreach($pop […]

WordPress Insert not working with ajax

I am trying to enter insert data with form in wordpress and want to use ajax for that. Without ajax it works fine but when I use ajax pressing the submit button gives 0 in result and the data is not inserted to the database . Below is my code. Html code is between form […]