$wpdb->get_var returns 0

Your count for that query may be 0. Make sure $wpdb->tablex is correct. Also, definitely use $wpdb->prepare $user_followed = $wpdb->get_var( $wpdb->prepare( “SELECT COUNT( * ) AS total FROM {$wpdb->tablex} WHERE type = %d AND active = %d AND user_id = %d”, 4, 1, $user_id ) );

Query Problem in Clustom Plugin

It looks like your SQL succeeded to me. So I guess your problem is that you’re getting an array of results (which is probably an array of arrays: rows, then columns per row) when you were expecting a single scalar value. Try using get_var() to get a single value from the database: $DBPresults = $wpdb->get_var( … Read more

get only 1 wpdb and get taxonomy, post to next page [closed]

For 1st question $args = array( ‘post_type’ => ‘us_visa’, ‘posts_per_page’ => -1, ‘orderby’ => ‘post_date’, ‘order’ => ‘DESC’, ‘meta_query’ => array( array( ‘key’ => ‘_Passport’, ‘value’ => $passport_num, ) ) ); $query = new WP_Query( $args ); See Custom Field Parameters of WP_Query on Codex For 2nd question, inside the loop use <?php the_terms( get_the_ID(), … Read more

Can’t access data from database using AJAX

Pass data as an argument in done(function(data) funtion. <script> jQuery.ajax({ type:”POST”, url: my_ajax_object.ajax_url, data: { ‘action’: ‘call_my_ajax_handler’ } }).done(function(data) { console.log(data); });

query using wpdb in wordpress gets me no result

First of all, you escape that query incorrectly… You should use esc_like on the like part and prepare should be used a little bit different: $title1 = ‘Gocomma 10W QI Wireless Fast Charger Car Mount Holder – 2pcs (it)’; $sql = $wpdb->prepare( “SELECT * FROM {$wpdb->posts} WHERE post_title LIKE %s AND post_status=”publish””, ‘%’ . $wpdb->esc_like($title1) … Read more

how to use transient method?

First, you don’t need a raw SQL query, and by using one you give up all of WP’s optimisations. For example, if you run the query twice, it runs twice. If you had used WP_Query to getch those posts though, it would save them the first time to avoid making additional queries. It’s even possible … Read more

How to get one result using wpdb class?

You’ve made no attempt to check for errors, e.g. $result may be false, also your code would fail if there was more than one result returned. So instead of using a custom table, and reinventing the wheel, use the provided APIs: get_theme_mod and set_theme_mod So your code now becomes: function asec_get_link_color( $default_color=”blue”) { return get_theme_mod( … Read more

Fixing plugin for wpdb::prepare

The error you’re facing definitely isn’t coming from your code shown above. This is an error notice that was raised with WP 3.5 (IIRC) that should note that stand alone $wpdb->prepare( STATEMENT ); calls help nothing. Missing argument 2 for wpdb::prepare() tells you that you haven’t added any argument to the call. The prepare() method … Read more

How to delete field using WPDB?

You can’t “delete” a field in MySQL, this only works for complete rows. However, you can unset values, meaning setting them to their original state, usually NULL or an empty string. $wpdb->update($wpdb->posts, array( ‘product_rank’ => NULL ), array( ‘ID’ => $post_id ));

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)