How can I get the query that would be run for the archive page?

In each of your hooks & filters handlers, in addition to checking for archive conditions, check for a custom query var that you can then set for a custom/manual query. For example, where you might have: function wpse_223991_pre_get_posts( $wp_query ) { if ( $wp_query->is_main_query() && $wp_query->is_post_type_archive( ‘my_post_type’ ) ) { // Awesome custom stuff } … Read more

How to run a mysql query when admin updates user role?

You are going in wrong direction there is no way to get user role while admin change from back end. You can retrieve the role object for the current user by calling get_role(), but that’s an object rather than a string with the role name. function get_user_role($uid) { global $wpdb; $role = $wpdb->get_var(“SELECT meta_value FROM … Read more

Insert static element only once in query archive

Use the Index of the post currently being displayed to trigger when your custom content is rendered. current_post can be found on WP_Query from within the loop. <?php while( $archive_query->have_posts() ) : $archive_query->the_post(); ?> <article <?php post_class(); ?>> The Content </article> <?php if ( $archive_query->current_post === 2 ): ?> <div>Custom Content</div> <?php endif; ?> <?php … Read more

Change searched term

The pre_get_posts filter is the right place to go. You can check if you are on a search query, and alter it the way you want. Here’s an example: function search_filter($query) { if ( !is_admin() && $query->is_main_query() ) { // Check if we are on a search page if ($query->is_search) { // Get the search … Read more

Using $wpdb->update but confused on the WHERE in and SET

You need to look at the documentation for the function, which is available here. The function takes the following arguments: $table The table name. $data A PHP array where the keys are the columns and the values are the the values to be inserted into those columns. $where A PHP array where the key is … Read more

Strange string in console from wpdb query

That is a placeholder escape string generated by wpdb::placeholder_escape() which is used by wpdb::add_placeholder_escape() and which is called by wpdb::prepare(). So it is safe to keep those escape strings, but there is a wpdb method for removing them: wpdb::remove_placeholder_escape(): // In your case, you’d use $this->wpdb in place of $wpdb. $query = $wpdb->add_placeholder_escape( ‘LIKE %night%’ … Read more

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