Check if a value exists in database table

Replace this: $result = $wpdb->get_row(“SELECT * FROM wp44_predefined_address WHERE ‘UPPER(Address1)’ LIKE ‘UPPER(%s)'”, $myinput); with this: (just choose the appropriate $like based on your requirements) // Properly generate the LIKE query. $like=”%” . $wpdb->esc_like( $myinput ) . ‘%’; // e.g. ‘%input%’ //$like=”%” . $wpdb->esc_like( $myinput ); // e.g. ‘%input’ //$like = $wpdb->esc_like( $myinput ) . ‘%’; … Read more

Assign all Post in Wp to a specific Category

Find out the ID of the category that you want to assign. You’ll see it in the URL when editing the category (URL will be something like ?taxonomy=category&tag_ID=3&post_type=post, here 3 is the ID) Assuming that the ID is 3, you can now run this query in your database (eg via PHPMyAdmin) INSERT IGNORE INTO wp_term_relationships … Read more

Slow Query On Search

This is the query generated by the internal search function on WordPress. It is criticised for being inefficient, and there are a few drop-in replacements available as plugins. You may be able to find something that helps you by doing more research around these. For example: https://themeisle.com/blog/improve-internal-search-in-wordpress/ https://winningwp.com/best-wordpress-search-plugins/ I don’t have a specific recommendation to … Read more

DB Query not working in Plugin

Looking at the SQL query in $createSQL, ENGINE=InnoDB” . $wpdb->get_charset_collate() . ” AUTO_INCREMENT=1; yields to: Error in query (1286): Unknown storage engine ‘InnoDBDEFAULT’ To fix it, add a space between the ENGINE=InnoDB (the storage engine) and ” . $wpdb->get_charset_collate() (the charset). You have defined the column id as AUTO_INCREMENT, but the column is not a … Read more

Update all published posts at once

I would have preferred to put this as a comment, but space does not allow for it so sorry about that. It might help you rather than being an answer. I am using ‘product’, but it could just as easy be ‘post’. function update_all() { $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => -1, ); … Read more