post__in for get_posts with a dynamic array

Here’s one way by using wpdb::get_col() and fetch the id column: $pids = $wpdb->get_col( “SELECT id FROM my_table” ); We could then clean it by integer convert each id with: $pids = wp_parse_id_list( $pids ); Just note the different max value for intval(), depending on 32 or 64 bits systems.

Get total number of comments from posts in a specific custom taxonomy

You’ll need to loop through your posts, use get_comments_number() to get the number of comments for each post, and then accumulate the total number of comments in a separate variable. e.g.: <?php $features_comment_count = 0; if ( have_posts() ) : while ( have_posts() ) : the_post(); $features_comment_count += get_comments_number(); endwhile; endif; ?> (I’ll assume that … Read more

prepare() not working

I agree with @bainternet. You don’t need $wpdb->prepare. There isn’t any user supplied content. The answer to the question is that to get a wildcard % to pass through prepare you need to double it in your code. LIKE ‘_transient_wb_tt_%%’ Try that or this if you want a good look at the generated query: var_dump($wpdb->prepare(” … Read more

How might I retrieve a featured post image from an external WP site and display it as a link back?

Whenever I’m trying to link two sites, I find the most efficient and least destructive way is to use the WordPress XMLRPC API. http://codex.wordpress.org/XML-RPC_WordPress_API/Posts In this case, you could pull this info through using the built in IXR_Client library. This saves a ton of time writing code and trying to mix databases. If they wind … Read more

Change post status based on meta value

Your code looks okay, and considering you are not submitting user entered data, the prepare() method isn’t required, but as a matter of best-practice it’s good to learn how it works and use it consistently. With that said, using the prepare() method, your code would look like this: $sql = $wpdb->prepare( ” SELECT ID FROM … Read more

Multipart/formatted MySQL query problem

After much trial and error I finally figured out a solution using mysqli. I consider it a acceptable solution since the query will only be run on plugin updates. $mysqli = new mysqli(); $mysqli->connect(DB_HOST, DB_USER, DB_PASSWORD, DB_NAME); $sql = ” DROP TRIGGER IF EXISTS {$wpdb->get_blog_prefix($site->id)}post_queue_insert; CREATE TRIGGER {$wpdb->get_blog_prefix($site->id)}post_queue_insert BEFORE INSERT ON {$wpdb->get_blog_prefix($site->id)}posts FOR EACH ROW … Read more

Custom query to get post names beginning with a digit

The solution given by @RolandoMySQLDBA will give you all posts because you have a * and not a +. The * means to return zero or more matches, which is not what you want. In this case, you actually don’t need either, but just to match the first character. Try this: $sql .= $wpdb->prepare( ” … Read more

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