Sorting custom taxonomy causes menus error

Currently your code is modifying all term queries, both in the front-end and in the back-end. Each navigational menu is registered as a term in the nav_menu taxonomy, so when you visit the backend to work on the menus, those queries have been modified too by your code snippet. For example, I don’t see any … Read more

Alter query on edit.php

Few days ago I wrote a quick solution using pre_get_posts filter to hide some pages in admin area. Maybe you could use it as a good starting point for whatever you’d like to achieve. if ( is_admin() ) add_filter(‘pre_get_posts’, ‘mau_filter_admin_pages’); function mau_filter_admin_pages($query) { $query->set(‘post__not_in’, array(1,2,3) ); // Do not display posts with IDs 1, 2 … Read more

How to properly sanitize strings without $wpdb->prepare?

I can’t use $wpdb->prepare, since I want to be able to add variables to my query string that look something like: $var = “AND pm.meta_value=”%$_POST[“val’]%'”; To get a literal % to pass through $wpdb->prepare just double it. You don’t need to be avoiding $wpdb->prepare. Proof of concept: var_dump($wpdb->prepare(‘SELECT * FROM {$wpdb->posts} WHERE post_title LIKE “%%%s%%”‘,’Hello’)); … Read more

“#1067 – Invalid default value for ‘post_date'” when trying to reset AI after backup

The post_date default value is 0000-00-00 00:00:00. If you check the sql_mode variable like this: show variables like ‘sql_mode’; … it will show you the sql_mode variable, that will be sth like this: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION You have to set up again sql_mode variable without NO_ZERO_IN_DATE,NO_ZERO_DATE So in the previous example you should set the sql_mode like … Read more

Extending WP_Query — Optimise SQL query

Here’s an idea, however it will require the ability to make custom SQL queries – with $wpdb. Since you want to get posts followed by a user, you can create a view, with the following structure: id user_id post_id post_title post_content … (all other post fields) don’t worry about duplicating posts. When you select, you … Read more

prepare() not working

I agree with @bainternet. You don’t need $wpdb->prepare. There isn’t any user supplied content. The answer to the question is that to get a wildcard % to pass through prepare you need to double it in your code. LIKE ‘_transient_wb_tt_%%’ Try that or this if you want a good look at the generated query: var_dump($wpdb->prepare(” … Read more

Multipart/formatted MySQL query problem

After much trial and error I finally figured out a solution using mysqli. I consider it a acceptable solution since the query will only be run on plugin updates. $mysqli = new mysqli(); $mysqli->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql = ” DROP TRIGGER IF EXISTS {$wpdb->get_blog_prefix($site->id)}post_queue_insert; CREATE TRIGGER {$wpdb->get_blog_prefix($site->id)}post_queue_insert BEFORE INSERT ON {$wpdb->get_blog_prefix($site->id)}posts FOR EACH ROW … Read more

Organizing WP Pages based on old website database

Before getting into Importing, I would familiarize yourself with both the standard post type and post_meta as well as custom post types and taxonomies. If your end goal would benefit from the latter, you will save yourself quite a bit of headache utilizing them during the import preparation. If you prefer working with the database … Read more

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