Make a loop to return x number of posts, but only if they have content or excerpt

Below is an example — tested and worked. The SQL query is: AND ({$wpdb->posts}.post_content != ” OR {$wpdb->posts}.post_excerpt != ”) And the example: <?php // This would be in functions.php or somewhere else where appropriate. function posts_where_require_content_or_excerpt( $where, $wp_query ) { global $wpdb; $where .= ” AND (” . ” {$wpdb->posts}.post_content != ”” . ” … Read more

How can i restore only Blogs from a SQL backup file?

“Blogs” or posts as they are called in WordPress are stored in the wp_posts table of your database. And custom fields related to your posts are stored in wp_postmeta table. So you should just be able to restore those two tables to get all your “Blogs”. This assumes your database is prefixed with wp_ of … Read more

SQL query to set posts in bulk based on the post content

Look into MySQL Wildcards. The correct MySQL Query for your search should be WHERE tb_posts.post_content LIKE “%example.com%” You should also be sure that you only target published posts (in contrast to nav_menu_items, revisions etc). Expand your WHERE with this: AND tb_posts.post_type IN (‘post’,’page’,*All Posttypes you use additionally*) AND tb_posts.post_status=”publish” So your complete Query should look … Read more

PHP -> SQL Query with Summing

Looking at this, I see that “Paid”, a string, isn’t in quotes. That would cause an error. You can add $wpdb->show_errors() and $wpdb->print_error() methods to reveal that, and any other mysql issues. Also when querying the database, you should use the $wpdb->prepare() method to escape and prepare your variables for query (yes $user->ID probably can’t … Read more

Deactivation Hook does not remove database

function my_plugin_remove_database() { global $wpdb; $db_table_name = $wpdb->prefix . ‘sandbox’; // table name $sql = “DROP TABLE IF EXISTS $db_table_name”; $rslt=$wpdb->query($sql); } register_deactivation_hook( __FILE__, ‘my_plugin_remove_database’ );

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

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