$wpdb sql help. Select post id and post meta value based on 2 other post_meta values

$post_this_month = $wpdb->get_results($wpdb->prepare(” SELECT key1.ID, key1.post_title, days.meta_value as days FROM $wpdb->posts key1 INNER JOIN $wpdb->postmeta days ON days.post_id = key1.ID AND days.meta_key = %s INNER JOIN $wpdb->postmeta startdate ON startdate.post_id = key1.ID AND startdate.meta_key = %s INNER JOIN $wpdb->postmeta enddate ON enddate.post_id = key1.ID AND enddate.meta_key = %s WHERE days.meta_key = %s AND startdate.meta_value <= … Read more

Delete/replace img tags in post content for auto published posts [closed]

You can use the function get_posts to get all your post, and then use a foreach cycle to replace the img tags using the regex you posted and then use wp_update_post to change post content: function remove_images_form_past_posts() { if ( get_transient(‘images_removed_from_past’) ) return; $posts = get_posts(‘nopaging=1’); if ( $posts ) { foreach ( $posts as … Read more

Dynamic URL, not a physical page within the database

add_rewrite_rule can help you sniff the request and let you handle it however you want. if( ! class_exists(‘PropertiesEndpoint’)): class PropertiesEndpoint { // WordPress hooks public function init() { add_filter(‘query_vars’, array($this, ‘add_query_vars’), 0); add_action(‘parse_request’, array($this, ‘sniff_requests’), 0); add_action(‘init’, array($this, ‘add_endpoint’), 0); } // Add public query vars public function add_query_vars($vars) { $vars[] = ‘__properties’; $vars[] = … Read more

Quotes in table name

How can I fix this? You can’t, but it isn’t broken. You are telling prepare to use a string. A string will be quoted. It isn’t meant to generate MySQL syntax, which is what you are asking it to do. Your tablename is more a MySQL command or keyword than a string value. That isn’t … Read more

Missing argument 2 for wpdb::prepare() Issue

That was not exactly change in code, that was change to better inform people they are not using the method correctly. In line with wpdb documentation you need to properly pass values, or they won’t be properly escaped in query. In your case it would turn into something like: $wpdb->prepare(“SELECT id, name FROM %s”, $table_name) … Read more

Connecting to external oracle database

You can’t use WPDB to connect to databases that aren’t MySQL/MariaDB based. There are no WordPress APIs or WP based solutions that will do this. Instead you will need to use a general PHP solution inside your plugin, and should look at general PHP resources and communities, not WP ones. I can also guarantee, that … Read more

Custom $wpdb Query for Custom Post Type by Category

Don’t use $wpdb, use wp_query. Not only will your code be leaner and quicker, you’ll avoid issues like this. Unless you’re doing something with custom tables or seriously in-depth SQL, there’s no reason to do direct SQL calls on $wpdb. So, to answer your question – rewrite it from the ground up using wp_query, see … Read more

Querying Email Addresses for a List of Users with Same Last Name?

Hi @Holidaymaine: Here’s the query you are looking for: <?php include( ‘../wp-load.php’ ); $sql =<<<SQL SELECT DISTINCT u.user_email AS user_email, um.meta_value AS user_lastname FROM {$wpdb->users} AS u LEFT JOIN {$wpdb->usermeta} AS um ON u.ID = um.user_id LEFT JOIN {$wpdb->posts} AS p ON u.ID = p.post_author LEFT JOIN {$wpdb->term_relationships} AS tr ON p.ID = tr.object_id LEFT … Read more

Getting users who registered 360 days from current date

I peeked into the WP_User_Query class and it supports a WP_Date_Query query on the user registration date. So we could use: $query = new WP_User_Query( $args ); or simply: $users = get_users( $args ); where: $args = [ ‘fields’ => ‘ID’, ‘number’ => 8, ‘date_query’ => [ [ ‘before’ => ‘359 days ago midnight’ ], … Read more

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