My SQL function to change user_name
This should be working: Be sure that your DB prefix is “wp_” Update wp_users set wp_users.user_login=wp_users.user_nicename where wp_users.user_login=”x”
This should be working: Be sure that your DB prefix is “wp_” Update wp_users set wp_users.user_login=wp_users.user_nicename where wp_users.user_login=”x”
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
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
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
One disadvantage of using that SQL query is that the slug will only be updated when you really go edit the post. Plus, it might cause odd behavior when any plugin tries to do something with an empty slug. A good alternative would be to use WP-CLI instead. First, you’ll need a list of all … Read more
I think you can achieve this by adding a query var. And then you can use something in pre_get_posts like this: if ( get_query_var( ‘your_var’ ) ) { // do something }
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
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
You can’t easily query inside arrays inside a meta value. This is because there’s no such thing as an array value in MySQL. Instead the value is stored as a serialized string. So an array like this: array( 0 => 29, 1 => 28, ); Is stored in the database as this string: a:2:{i:0;i:29;i:1;i:28;} So … Read more
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