SQL query not working in alphabetical post title/content search

Dude, no need of the SQL mess! WP allows you to search through the post content or titles alphabetically using the search parameter. So, use this solution instead… global $wpdb; $q = $_REQUEST[‘q’]; $posts = get_posts(array(‘s’ => $q, ‘post_type’ => ‘question’, ‘posts_per_page’ => -1)); echo ‘<ul>’; foreach($posts as $post){ echo ‘<li><a href=”‘.get_permalink($post->ID).'”>’.$post->post_title.'</a></li>’; } echo ‘</ul>’; … Read more

$wpdb->insert – inserting multiple rows

I guess the problem is a pretty simple one. You didn’t show the whole code, but I guess the problem is that you’re saving the insertion for some unknown reason as string into a var named $stat. Everytime you fill the var with a new query you’re overwriting your var. You should use $stat .= … Read more

wpdb prepare syntax

Just look at the generated string: INSERT INTO ‘wp_table’ (id, datea, one, two) VALUES (1, ‘2013-12-24’, 3, ‘NULL’) ON DUPLICATE KEY UPDATE one = VALUES(one), two = VALUES(two); The problem is the quotes around the table name. (Your hand-written query has no quotes around the table name, and works.) prepare is intended for dynamic user … Read more

ob_end_flush error when using wpdb in plugin

You did not provide that information, so I have to guess a little bit: You are using PHP 5.4 and zlib.output_compression is on on your server? Then you just stumbled upon bug #18525. Possible solutions: Disable zlib.output_compression. Apply the patch provided there and report back on that ticket if it works. Disable notices. What you … Read more

Can’t pass table to $wpdb->prepare

The prepare() method escapes %s. The second piece of code you listed breaks because quotation marks are added to the table name, hence it doesn’t match what’s in the DB. The first piece of code works because it’s a straight string replacement hence matching the name of the table in the database. What is the … Read more

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