Checking if meta_value exists for any user

I personally try to stay away from mysql queries when I can use WordPress functions to achieve the same thing. You could try using get_users, Is this what you are trying to achieve: <?php $blogusers = get_users(‘meta_value=Referral’); foreach ($blogusers as $user) { echo $user->user_email; } ?> Untested. But that should display every user with a … Read more

Can’t get expected result from a wpdb query

I know I probably can’t see the full picture, but in the excerpt you provided isn’t globalizing $post. global $wpdb, $post; $short = $wpdb->get_var(“SELECT url FROM $wpdb->prefix.’tweet_url’ WHERE post_id = ‘$post->ID’ “);

Using $wpdb to update current post

Nevermind, I was complicating this whole process because I wasn’t thinking about just using get_post_meta(). add_action(‘draft_to_publish’,’gcpl_draft_to_published’); function gcpl_draft_to_published($post){ $exp_processed = get_post_meta($post->ID, ‘_expiration-date-processed’, true); // check if the custom field has a value if($exp_processed != ”) { delete_post_meta($post->ID, ‘_expiration-date-processed’); } }

SQL Query to select post title & post ID from a particular category

You can use $args = array( ‘post_type’ => ‘post’ ,’posts_per_page’ => 10, ‘category_name’ => ‘orange’ ); $query = new WP_Query( $args ); printf( ‘<h2>Generated SQL:</h2><pre>%s</pre>’, $query->request ); to display the generated SQL query. The above example will give you: <h2>Generated SQL:</h2> <pre> SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) WHERE … Read more

Retriving array size from serialized data

Your Query is wrong beacuse your are searching for the user_id inside the meta_value column instead of the user_id column. In this case i see no point in creating a custom query just for that, So here is how you can do it using the native function get_user_meta $data = get_user_meta( get_current_user_id(), ‘bookmark_posts’ ); $number … Read more