$wpdb in php 5.5

There is no difference in this respect between PHP 5.3 and 5.5. The code doesn’t need to change. However, you should still use prepare properly. Like so: $query = $wpdb->prepare( ‘UPDATE wp_building_plan SET sale_price = %s, available = %s, broker_name = %s, broker_email = %s, broker_phone = %s WHERE id = %s’, $sale_price, $available, $broker_name, … Read more

List users with the most posts in the last 30 days

Here is what you need. <?php $date = new DateTime(‘NOW’); $date->sub(new DateInterval(‘P30D’)); //30 Days Interval echo $back30days= $date->format(‘Y-m-d H:i:s’) . “\n”; global $wpdp; $top_users = $wpdb->get_results(“select count(users.user_nicename) as posts, users.user_nicename as user_name from $wpdb->users as users join $wpdb->posts as posts where users.ID = posts.post_author AND posts.post_status=”publish” AND posts.post_date_gmt > ‘$back30days’ GROUP BY users.user_nicename ORDER BY … Read more

WP MS: How to query over the network

[*] Each site in a Multisite network is considered to be exactly that — a separate site. All the $wpdb values (eg, $wpdb->posts) are distinct for each site. You can use switch_to_blog() and restore_current_blog() to get content (posts, etc) from the various sites[*] in your network: $sites = array( 1, 2, 3, ); $all_posts = … Read more

Undefined variable: row?

First, it’s not $wpdb->wp_posts, it’s just $wpdb->posts. Second, you’re using prepare() incorrectly. You use prepare when you have some variable data that you need to safely insert into the query string, not otherwise. Using prepare on a known string does nothing and throws a warning. For example: $data=”example string” $query = $wpdb->prepare(“SELECT post_title FROM {$wpdb->posts} … Read more

How to access the WordPress DB from a plugin file

If you plan to share/sell your plugin I strongly suggest don’t load your plugin directly. That because to load WordPress you need to load the bootstrap file, that is /wp-load.php so, you should put in your embed-video.php something like: require ‘/wordpress/path/wp-load.php’; Do you notice the problem here? The /wordpress/path/ part is different for user to … Read more

Get the alphabetical sorted data with wpdb

It isn’t really WordPress-related indeed, but then again, OP doesn’t seem to know that, so here’s your answer :-). However, next time: this isn’t WordPress-related, please post PHP-questions in the corresponding SE. Sorting a PHP array can be achieved by using the sort function, which sorts an array alphabetically by its values. I’m assuming you … Read more

Perform a function when a user clicks register button

You can hook your function with user_register. It will fire immediately after an user registration is done. And user id is passed to hook as an argument. add_action( ‘user_register’, ‘my_custom_function’ ); function my_custom_function ( $user_id ) { //here goes your code }

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