wpdb

wpdb select query to get certain meta_key?

I have the below code where I am trying to get a list of orders. So from the wcomm (woocommerce_order_itemmeta) table, I only want to display the meta_value where the meta_key is equal to _qty or _product_id and I need the _product_id to be filtered on a single value like I have. I can’t seem to make it only do…
Read more

$wpdb – sort by two meta value

I have “type” custom field and two value (free and paid). I need get “paid” posts first in loop, and free latest. How can I sort my query? I can’t use wp_query. global $wpdb; $query = ” SELECT * FROM $wpdb->posts INNER JOIN $wpdb->postmeta m1 ON ( $wpdb->posts.ID = m1.post_id ) WHERE $wpdb->posts.post_type = ‘object’ AND $wpdb->posts.post_status = ‘publish’ AND…
Read more

WordPress broken after wpdb in functions.php

I am working on a little function in the functions.php of my theme to redirect to a another url and send some data with POST when a user completes a order. But I need to send the quantities of a item. When I comment out the wpdb funtion it works and if I uncomment it , it will break the…
Read more

How to decrease load time of join query in wordpress?

I am using $wpdb Object to display some data in WordPress post loop. while ( have_posts() ) : the_post(); echo ‘<li>’; the_title(); echo ‘</li>’; endwhile; The code I want to put in that loop is: <h3><font color=”#F60″><?php global $wpdb; $result = $wpdb->get_results($wpdb->prepare( “SELECT * FROM `link` gl, `social` ls WHERE `sd`= 12 AND gl.lik = ‘$lisd’ AND gl.lik_id = ls.lik_id…
Read more

WordPress AJAX: Updating wp theme options table as well $wpdb (external DB)

Hy Guys, I have a wordpress theme admin page which stores most theme options in wordpress’s wp-option table, and some admin form meta info stored in a custom database (outside wordpress). External DB conn info and sql queries for custom db is included (<?php include(‘db_include.php’); ?>) in the main theme-option.php. The structure is shown in the image below: The submit…
Read more

$wpdb->query(update table) not working as supposed when passing GET request in the where clause

I have made a table ‘wp_mostfavourite’ in wordpress database, it has got three fields, ‘serialno’, ‘postid’, ‘counts’. The ‘counts’ is supposeto increased by 1, whenever the following query is processed. $postids = $_GET[‘action’]; // I tried stripslashes($_GET[‘action’]) as well, the query is not working $querycount=”update wp_mostfavourite set counts = counts+1 where postid = $postids”; $wpdb->query($querycount); After running, this query changes…
Read more

$wpdb->query(update table) not working as expected when passing GET request in the where clause

I have made a table ‘wp_mostfavourite’ in wordpress database, it has got three fields, ‘serialno’, ‘postid’, ‘counts’. The ‘counts’ is supposed to increased by 1, whenever the following query is executed. $postids = $_GET[‘action’]; // I tried stripslashes($_GET[‘action’]) as well, the query is not working $querycount=”update wp_mostfavourite set counts = counts+1 where postid = $postids”; $wpdb->query($querycount); But after running, this…
Read more

Fatal error when using update() in $wpdb class

I am trying to update a custom table in my WordPress database, but I keep getting this error: Fatal error: Call to a member function update() on null in /Users/jlf/project/wp-admin/controls.php on line 21 This is my PHP: ini_set(“display_errors”,1); error_reporting(E_ALL); $accentColor = $_POST[“accentColor”]; $donateColor = $_POST[“donateColor”]; $donateHover = $_POST[“donateHover”]; $ticketStatus = $_POST[“ticketStatus”]; $logoPath = $_POST[“logoPath”]; $characterPath = $_POST[“characterPath”]; global $wpdb; $q_result…
Read more

unable to insert data into wordpress db using form

When i click on submit it doesn’t create new posts in the posttype. It just refreshes the page.The below is a pagetemplate assigned to page. <?php if(isset($_POST[‘submit’])){ global $wpdb; $wpdb->insert( ‘contacts’, array(‘post_title’=>$_POST[‘name’],’email’=>$_POST[’email’])); } ?> <form method=”post” action=””> <input type=”name” id=”inputName” placeholder=”Name”> <input type=”email” id=”inputEmail” placeholder=”Email”> <button type=”submit”>SUBMIT</button> </form> Source: wpdb