Proper way to work with wpdb to get user’s firstname
You should’nt really be using wp query here, use get_user_meta(); Example: $first_name = get_user_meta(2, ‘first_name’, true);
You should’nt really be using wp query here, use get_user_meta(); Example: $first_name = get_user_meta(2, ‘first_name’, true);
I had the same problem. I did not have pre-existing menus, but newly created ones had the same symptoms as you described. In my case, the problem was a ill-defined table wp_terms. It was missing the AUTO_INCREMENT flag on the column term_id as well as all indexes and the primary key. I can only assume … Read more
Here’s the culprit: [meta_query] => Array ( [0] => Array ( [key] => city [value] => Las Vegas [compare] => = ) ) Meta queries are slow, and the only way to speed them up is to not use meta queries. The post meta table is optimised for fetching key/value pairs where the post ID … Read more
The WordPress current_time() returns the current time in the format specified in the first parameter. In your example code, this is the mysql value. The second parameter represents a timezone option. The default returns the local time for the timezone specified on the site’s Settings > General page, or GMT depending on the value supplied … Read more
TL;DR This is not possible with wpdb. Use dbDelta(). Even better, use something else to run raw queries. Explanation wpdb->query() uses the mysql_query() function. From PHP manual: mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that’s associated with the specified link_identifier. In order for that … Read more
OMG… No, no, no!!! Never do that this way… Why? There are many reasons… You won’t be able to do anything with users in your views.php – what if you’ll have to count only views by anonymous (not logged in) users? What if table_prefix is set to ”? Your posts table will cause conflicts… What … Read more
It turns out that it was due to Query Monitor, a plugin that records info about each query. Every time update_post_meta ran, Query Monitor would store some data about the query, which eventually added up to be more than the server could handle. Running my example code on a default theme like Twenty Nineteen with … Read more
But how does the actual HTML get on the page? How does that SQL data translate into a page full of blocks? Normally the HTML for a block is inside the HTML comments. However, much like shortcodes, ACF blocks are rendered in PHP, so when the post is processed during the_content filter, that block is … Read more
On your if(), it should be like this: if (!($wpdb->get_row(“SELECT voter_ip FROM ” . $wpdb->prefix . “voter_ips WHERE post_id = $post_id AND voter_ip = ‘$voter_ip'”) Notice the quotation mark added on $voter_ip.
Your template code includes $wpdb->print_error(). This function prints the last database error between [ and ] brackets, and the executed SQL code. But if there is no error, you just see the empty brackets and the SQL. $wpdb->show_errors() is used to enable displaying of database errors. If you want to see all database errors, you … Read more