Query the WordPress database to get data together with replaced information

This query worked for me. I had to reverse it, starting at the user and then matching the post ID. You would need to replace the value of wp_posts.ID of course. SELECT wp_users.ID FROM wp_users LEFT JOIN wp_postmeta ON wp_postmeta.meta_value = wp_users.user_email AND wp_postmeta.meta_key = ‘_from_email’ LEFT JOIN wp_posts ON wp_posts.ID = wp_postmeta.post_id AND wp_posts.ID … Read more

Database hacked – random posts are modified

It’s possible that the random stuff is not in the database; your answer doesn’t make that clear. There could be some modified WP files that are inserting text in each displayed post. Recovering from a hacked system is time-consuming, but can be done. Short list: update WP/themes/plugins to latest versions. Check the htaccess file against … Read more

mysqldump to a tar.gz

mysqldump –opt <database> | gzip -c | ssh user@wherever ‘cat > /tmp/yourfile.sql.gz’ You can’t use tar in a pipe like this, and you don’t need it anyway, as you’re only outputting a single file. tar is only useful if you have multiple files.

Some Post Content Does Not Show Up In DB Search

WordPress store the content from the editor inside the table post_content. But if you use additional plugins for your editor it is possible to store on different places, like custom tables and also in post_meta, really popular for third plugins to store date there use the meta API. Small hint, maybe you should use a … Read more

External wpdb connections in different plugins on single page

You’ll have to make the variable global when you define it, e.g. global $mydb; $mydb = new wpdb(‘username’,’password’,’database’,’localhost’); and then use global $mydb; in the other plugins. Aside from theme files, functions.php, and plugins while being loaded, pretty much nothing in WP runs in global context, so if you need to access global variables, you’ll … Read more

mysql query – how to escape apostrophe?

Use esc_html() when outputting a string value inside tags. Use esc_attr() when you’re outputting a string value inside an attribute=””. If you’re outputting a URL, use esc_url() instead of those two. if ($tenantsInfo) { foreach ($tenantsInfo as $tenant) { echo “<h2>Welcome, ” . esc_html( $tenant->tenant_name ) . “</h2>”; } }

Bulk append URL (add word to slug)

Here is your code: if ( isset($_GET[‘slug-update’]) ) { $posts = get_posts(); foreach($posts as $singlepost) { if($singlepost->post_status === ‘publish’){ $post_id = $singlepost->ID; $current_slug = $singlepost->post_name; $updated_slug = $current_slug . ‘-word’; } wp_update_post( array( ‘ID’ => $post_id, ‘post_name’ => $updated_slug ) ); } die(‘Slug Updated’); } Add this to your theme’s function.php. Then run this with … Read more