Why would switch_to_blog stop working?

It appears that switch_to_blog might be too unpredictable to rely on for major site design. Here’s my first attempt at a SQL-based solution. function get_intro_post($blogid, $thumb_size=””) { global $wpdb, $post; // Get the system defined table prefix $prefix = $wpdb->prefix; // Create a full table prefix by combining the system prefix with the blogid $tbl … Read more

Detect featured image among the attached images

Simply add an post__not_in argument and use the get_post_thumbnail_id() function. $args = array( ‘post_type’ => ‘attachment’, ‘post_parent’ => $product_id, ‘post_mime_type’ => ‘image’, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘numberposts’ => -1, ‘post__not_in’ => array(get_post_thumbnail_id($product_id)) ); $attachments = get_posts($args);

WordPress get pagination on wpdb get_results

You say “However, I know this is not a good way to do this” in your self answer. One thing I could add answering your question and using your answer is, you can use SQL_CALC_FOUND_ROWS with $wpdb $result = $wpdb->get_results( “SELECT SQL_CALC_FOUND_ROWS * FROM `wp_table` WHERE 1 LIMIT 10;” ); $total_count = $wpdb->get_var( “SELECT FOUND_ROWS();” … Read more

Join inside a wpdb query.. confused!

$emailusers = $wpdb->get_results( “SELECT p.ID AS post_id, p.post-title, u.user_email ” . “FROM $wpdb->posts AS p ” . “INNER JOIN $wpdb->users AS u ON p.post_author = u.ID ” . “WHERE p.post_type=”sales” AND HOUR( TIMEDIFF( NOW( ) , p.post_date_gmt ) ) >=1)” ); foreach ($emailusers as $user) { // do wp_mail stuff from here // $emailusers->post_title; // … Read more

$wpdb->replace / Replace or update primary key

You Can use This solution.. How to delete all records from or empty a custom database table? In this solution First delete all records an then insert new records (your table should be have records before to delete query because If run $delete you give error ‘No find row’ ) and No need to use … Read more

How to email user after inserting the username in database in WordPress

Assuming that $member_details->user_login is already a user in the wp_users table, then you could use the following to get their email address: $user = get_user_by( $member_details->user_login, ‘login’ ); From there, you have the user’s email address and can use wp_mail() to email them: $subject = “My email subject”; $message = “My message body…”; wp_mail( $user->user_email, … Read more

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