I have custom table like this: useraw 1. id (Primary*) 2. user_ip 3. post_id 4. time I am inserting data in the table using $wpdb->insert($table_name , array('user_ip' => $user_ip, 'post_id' => $postID, 'time' => $visittime),array('%s','%d', '%d') ); There are four rows I inserted using this code: id : 245 user_ip : 245.346.234.22 post_id : 24434 time : 255464 id : 345 user_ip : 245.346.234.22 post_id : 23456 time : 23467 id : 567 user_ip : 245.346.234.22 post_id : 57436 time …
Is there a way to save template data into wp_post table? I made a custom template that automatically makes tables and some sentences with the meta-data that users insert in. I wanted to make users choose a template and write in a standardized format with custom field. Users can now just put some text on my custom field (bottom of my post edit page) and click the template on the sidebar, then the contents show on the post page! And …
I'm using gravity forms for a sign-up form and I set up a hidden field that is automatically filled with a random string generated and passed to the form by add_filter("gform_field_value_random_number", "generate_random_number"); function generate_random_number($value){ $value = substr(str_shuffle(str_repeat("0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" ,5)), 0, 7); } This is to use as a unique coupon code/user.This field also appears in their user profile. Up to here all is well. Where I'm having trouble is checking the database that no user already has that coupon code. At …
I want to exclude Subscribers from a user list. My code is: $users = $wpdb->get_results( "SELECT display_name FROM $wpdb->users ORDER BY display_name ASC" ); How can I change that so subscribers are excluded from the list? I also looked at the get_users function in codex but it did not have an exclude by role parameter. Edit: Or another way would be to get the results filtered by capability (one that subscribers doesn't have).
I want to disable user_login field into my CMS. They are register only their email adress. I think to create secret user login by programmatically. I think for accessibility and manageability also I want to use their ID'. For this I want to know last user's ID. I know the unprofessional way of doing this. A way as below, <?php $args = array( 'orderby' => 'registered', 'order' => 'DESC', 'number' => 1 ); $users = get_users($args); $last_user_registered_ID = $users[0]->ID; But …
I would like to get a list of user_nicenames and the ID. But not all the usernames which is what i'm getting now. I understand I should use the % before and after the $name only nothing seems to be working. This is the only way to get some output I found till now; global $wpdb; //get access to the WordPress database object variable //get names of all users $name = $wpdb->esc_like(stripslashes($_POST['name'])).'%'; //escape for use in LIKE statement $sql = …
I am trying to create custom admin widget to present how many users has registered within last days. I have created function as below: function mdbootstrap_add_dashboard_recent_users(){ global $wpdb; $query = " SELECT count(*) as counter, DATE(wp_users.user_registered) as regdate FROM wp_users GROUP BY DATE(wp_users.user_registered) ORDER BY DATE(wp_users.user_registered) desc"; $posts = $wpdb->get_results($query,OBJECT); print_r( $posts); } However for some reason it's returning only 2 rows: Array ( [0] => stdClass Object ( [counter] => 1 [regdate] => 2016-01-12 ) [1] => stdClass Object …
I'm using Cryto Plugin and want to get coin price data from plugin db. For easy practice, I'm trying to get BTC data. <?php function get_coin_price($coin_symbol) { global $wpdb; $coin_price = $wpdb->get_var($wpdb->prepare("SELECT price FROM {$wpdb->prefix}cmc_coins_v2 WHERE symbol = '%s'", $coin_symbol)); return $coin_price; }?> And if I want to get BTC price, I use this code. <?php get_coin_price(BTC); ?> However I'm getting this error "Use of undefined constant BTC - assumed 'BTC' (this will throw an Error in a future version …
Is it possible to create a table with the wpdb::prepare function? I read the documentation and tried to find examples but there where none that helped me. Even creating a table with prepare doesn't give me any useful examples on Google. Currently I'm creating my table like this: public function createTableFromFields( $tablename, $fields ) { // $wpdb = $this->db; $tablename = $wpdb->prefix . $tablename; $sql = 'CREATE TABLE IF NOT EXISTS ' . $tablename . ' (id INT(6) UNSIGNED AUTO_INCREMENT …
Is it possible with the standard build-in tools in Wordpress to get wp_query to only return the count of an query? Right now, I’ve a query which has several meta_queries but what the only thing I’m interested in is the actually count of the query. I know that I can use the found_posts property but the query itself generates a big overhead by query SELECT * and thus returns the whole object. I could just as easy query the DB …
I want to know that is it possible to fire a stored procedure once the plugin is activated? //action hook for plugin activation register_activation_hook( __FILE__, 'my_func' ); //function to create stored procedure function my_func() { //code goes here to create a stored procedure } Any help would be appreciated. Thank you.
I have a function which needs to create a new table an d i can't see for the life of me why it dosen't create the table: function afdv_create_delivery_table ( $id ){ global $wpdb; $charset_collate = $wpdb->get_charset_collate(); //table name composed of db prefix + delivery + company ID $table_name = $wpdb->prefix . "delivery_" . $id; $sql = "CREATE TABLE $table_name ( id int(10) unsigned NOT NULL AUTO_INCREMENT, userId int(10) NOT NULL, plati DECIMAL(10,2) NOT NULL, incasariCash DECIMAL(10,2) NOT NULL, incasariPvo …
I'm creating a personal plugin with more files and I need to connect to an external database with WPDB. At the moment I'm repeating "new wpdb(...)" in every function, in every file, of my plugin. Is there any way to put this instruction just ONE time?
What the code does: Imports posts, loops through all the posts and calls wp_insert_post to create a new posts for each import. Objective: Import posts and store them in another table, not under the wp_posts table, but retain the associated wp_postmeta tables. Issues: For some reason, in it's current state, the new table doesn't get created and the posts don't get inserted - What am I doing wrong? I'd like to import the posts to the new table. Since I …
A classifieds list site have only 3 criterias when searching products: the common search, category and region (for ZIP, city or full address) It's not enough and I really need to include a basic price system, so users can set a price range before searching. Looking at the theme files, I found the function for different queries, based in one or more of those criterias. The smaller is the query for only category, so I'll take it as example: elseif …
I have posts that have video content and these videos stored in database like this (serialized) a:1:{s:9:"video_url";s:0:"";} This serialized data have post video urls but can not get this data. I used <?php echo get_post_meta(get_the_ID(), '_custom_field', TRUE); ?> But this get_post_meta display output "array" instead of video urls
I have this code: $query = "SELECT * FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id INNER JOIN $wpdb->term_relationships ON $wpdb->posts.ID = $wpdb->term_relationships.object_id WHERE ((post_type = 'projects') OR (post_type = 'post_cost_codes'));"; $results = $wpdb->query($query); // Takes 1.5 seconds I also tried this: $query = "SELECT * FROM $wpdb->posts INNER JOIN $wpdb->postmeta ON $wpdb->posts.ID = $wpdb->postmeta.post_id INNER JOIN $wpdb->term_relationships ON $wpdb->posts.ID = $wpdb->term_relationships.object_id WHERE ((post_type = 'projects') OR (post_type = 'post_cost_codes'));"; $results = $wpdb->get_results($query); // Still takes 1.5 seconds But …
so if i have a function that gets terms from the database ( not the user ) do I need to use prepare first ( before get_results() ), or some sort of data sanitizing?
I am brand new to php and web development. I've made a front-end edit profile page for users, and every field updates except email (but, everything else is user meta). I have spent way too long on this to no avail. There are lots of posts about this, such as this one How do you update user_email on the front end in WP 3.3?, but I cannot get any of the methods suggested to work for me. I am using …
I have a query something like //read products with thumbnail and sku SELECT products.*, pm1.meta_value as sku, p1.guid as thumbnail FROM `wp_posts` as products LEFT JOIN `wp_postmeta` as pm1 ON products.ID = pm1.post_id LEFT JOIN `wp_postmeta` as pm2 ON products.ID = pm2.post_id LEFT JOIN `wp_posts` as p1 ON pm2.meta_value = p1.ID WHERE products.post_type = 'product' AND pm1.meta_key = '_sku' AND pm2.meta_key = '_thumbnail_id'; This Query will get all the products that have a sku and a thumbnail but will not …