$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 sql help. Select post id and post meta value based on 2 other post_meta values

$post_this_month = $wpdb->get_results($wpdb->prepare(” SELECT key1.ID, key1.post_title, days.meta_value as days FROM $wpdb->posts key1 INNER JOIN $wpdb->postmeta days ON days.post_id = key1.ID AND days.meta_key = %s INNER JOIN $wpdb->postmeta startdate ON startdate.post_id = key1.ID AND startdate.meta_key = %s INNER JOIN $wpdb->postmeta enddate ON enddate.post_id = key1.ID AND enddate.meta_key = %s WHERE days.meta_key = %s AND startdate.meta_value <= … Read more

Delete/replace img tags in post content for auto published posts [closed]

You can use the function get_posts to get all your post, and then use a foreach cycle to replace the img tags using the regex you posted and then use wp_update_post to change post content: function remove_images_form_past_posts() { if ( get_transient(‘images_removed_from_past’) ) return; $posts = get_posts(‘nopaging=1’); if ( $posts ) { foreach ( $posts as … Read more

Quotes in table name

How can I fix this? You can’t, but it isn’t broken. You are telling prepare to use a string. A string will be quoted. It isn’t meant to generate MySQL syntax, which is what you are asking it to do. Your tablename is more a MySQL command or keyword than a string value. That isn’t … Read more

wp-content/db.php : where is this file?

You would create your own dp.php file in the wp-content directory; if you define $wpdb in there, it will replace WordPress’s default $wpdb object. It’s not listed on the Pluggable Functions list (not a big surprise, as $wpdb is a class, not a function), but it seems similar in concept. Also, if you haven’t read … Read more

Get data from database table by post_id to get data from second database table

There are a couple things you need to do differently to make this work well. Make sure you’re setting $wpdb to the global. Use $wpdb->prefix instead of hard-coding wp_. Wrap your variables in curly braces. Use $wpdb variables instead of table names, like $wpdb->comments. Always always always use $wpdb->prepare() before performing a query. Using $wpdb->prepare() … Read more

passing variables as parameters to stored procedures via wpdb from php-script

Please take a look at the Codex to see how to prepare your statement: // Example straight copy-paste from Codex $metakey = “Harriet’s Adages”; $metavalue = “WordPress’ database interface is like Sunday Morning: Easy.”; $wpdb->query( $wpdb->prepare( ” INSERT INTO $wpdb->postmeta ( post_id, meta_key, meta_value ) VALUES ( %d, %s, %s ) “, 10, $metakey, $metavalue … Read more

Saving custom form data into database

OK, so here is how you should to this proper way… In your template file you put your form: <form id=”myForm” name=”myform” action=”<?php echo esc_attr( admin_url(‘admin-post.php’) ); ?>” method=”POST”> <input type=”hidden” name=”action” value=”save_my_custom_form” /> <select id=”brandSel” size=”1″> <option selected=”selected” value=””>– Select Brand –</option> <option>Abba</option> <option>AG Hair</option> </select> <input type=”submit” value=”submit” /> </form> And in functions.php … Read more

wpdb->insert not working

I got the same problem. Solution 1: Strip your data.. WordPress rejects the query if the length of value is greater than the field length defined on the database. On your insert query, the value for post_type field exceeded the 20 character limit. Solution 2: Use the $wpdb->query method