$wpdb->get_results not returning an array
It has nothing to do with $wpdb. It’s PHP parse error. print_r is a function, so you can’t do print_r $datarow; You should use print_r( $datarow ); instead.
It has nothing to do with $wpdb. It’s PHP parse error. print_r is a function, so you can’t do print_r $datarow; You should use print_r( $datarow ); instead.
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 }
You will have to define post order in second SQL query too. Try this one. // get years that have posts $years = $wpdb->get_results( “SELECT YEAR(post_date) AS year FROM wp_posts WHERE post_type=”post” AND post_status=”publish” GROUP BY year DESC” ); foreach ( $years as $year ) { // get posts for each year $posts_this_year = $wpdb->get_results( … Read more
As you can guess from version number this code is ancient. So ancient in fact that var keyword is from PHP 4 and is deprecated in PHP 5 (considered synonym of public for backwards compatibility). So inline doc hints it is private because back then there was no actual property visibility in PHP language. So … Read more
My SQL knowledge is quite bad, I should admit, so I’m going to use a non SQL way to achieve this. Here is my idea: Use pre_get_posts to alter the query variables before the main query is executed. As all of the query variable has been set by the time pre_get_posts run, you can simply … Read more
You should try to replace the meta_value = $list->ID part with the placeholder meta_value = %d. Then use the following: $subscriber_count = $wpdb->get_var( $wpdb->prepare( $q, $list->ID ) ); where the input argument $list->ID will be treated as an integer (signed). From the Codex: The query parameter for prepare accepts sprintf()-like placeholders. The %s (string), %d … Read more
Yes, you can pass an array of values. This is explained in the codex under Protect Queries Against SQL Injection Attacks value_parameter (int|string|array) The value to substitute into the placeholder. Many values may be passed by simply passing more arguments in a sprintf()-like fashion. Alternatively the second argument can be an array containing the values … Read more
option_name is type VARCHAR, iow. a string Try: $wpdb->get_var(“SELECT option_value FROM wp_options WHERE option_name=”siteurl””);
Trivial! $wpdb->last_query will hold it. 🙂 For more extensive log you might want to define SAVEQUERIES constant to true in configuration. Full log then will be available in $wpdb->queries. It’s off by default for performance reasons.
You can’t use wpdb::prepare to inject table names – just use “SELECT … $sidebar_table”