SQL Command for restoring trashed comments

I would discourage using raw SQL for moving a post to a trash or back, especially since there’s a build in function for it: wp_trash_post( $post_id ); More about the wp_trash_post() function. The opposite is: wp_untrash_post( $post_id ); wp_untrash_post() also untrashes trashed comments. In WP there are functions for many things – for instance you … Read more

Update table wp_term_taxonomy.count after INSERT INTO via SQL

You can just run the wp_update_term_count_now php function after doing this: https://developer.wordpress.org/reference/functions/wp_update_term_count_now/ Which calls the private _update_post_term_count https://developer.wordpress.org/reference/functions/_update_post_term_count/ If you look at the source of that you will see how term counts are updated (which is done when you save a post on backend): function _update_post_term_count( $terms, $taxonomy ) { global $wpdb; $object_types = (array) … Read more

WordPress website loads more posts than expected

The theme is most likely altering the main query via the pre_get_posts hook, chaning the posts_per_page argument to -1 for all posts, or another higher number. You can search your theme folder for pre_get_posts to see all the times this hook is used. A better solution would be to install the Query Monitor. With this … Read more

How can I prevent certain custom roles from seeing other custom roles on the user list page?

Method 1, SQL Notes about your SQL [Unknown column ‘wp_usermeta.meta_key’ in ‘where clause’] This is solved by adding this to the JOIN part of the query: JOIN wp_usermeta ON ( wp_usermeta.user_id = wp_users.ID ) You could check the value of the JOINS and, if false === strpos( ‘wp_usermeta’, $joins ), adding it yourself. When getting … Read more

Is it possible to query from external database? [duplicate]

You can use wpdb to setup a new connection. Add something similar to this below in your functions.php and you can then query just like you would normally but using the new connection. $second_db = new wpdb(DB_USER, DB_PASSWORD, $database_name, DB_HOST); $results = $second_db->get_results($your_query); references: https://wordpress.stackexchange.com/a/1673/86845 https://stackoverflow.com/a/36759606/3204142

SQL query, error

You have the where clause of the query in the wrong place. Your query should be written like this: $query= “SELECT * FROM files WHERE custom > 0 ORDER BY id DESC LIMIT $from, $site”; As specified here https://dev.mysql.com/doc/refman/8.0/en/select.html in the MySQL reference.

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