wpdb get_var is not returning any result (verified mysql query returns only one value)

I guess meta_key is not a number, so you shouldn’t use %d in yous SQL query. $wpdb->prepare( “SELECT meta_value FROM %s WHERE user_id = %d AND meta_key = %s”,$userMeta,$user_id,$practiceKey ); // meta_key = %s not %d PS. You don’t have to escape table name in this way. You can use $wpdb->prepare( “SELECT meta_value FROM {$wpdb->usermeta} … Read more

Custom query to show posts

You can do it with wp_query $args = array( ‘post_type’ => ‘post’, ‘numberposts’ => -1, ‘posts_per_page’=> -1, ‘orderby’ => ‘meta_value_num’, ‘meta_key’ => ‘ratings_average’, ‘order’ => ‘DESC’, ); $posts = new WP_Query($args); Now the result is DESC Order.

WP_Query based on multiple metadata comparisons

You could split this into two WP_Querys: $args = array( ‘post_type’ => ‘match_report’, ‘post_status’ => ‘publish’, ‘meta_key’ => ‘report_type’, ‘meta_value’ => ‘cup’, ‘fields’ => ‘ids’ ); $reportsPre = new WP_Query($args); $post_IDs = array(); if(isset($reportsPre->posts) && !empty($reportsPre->posts)){ foreach((array) $reportsPre->posts as $id) { $post_IDs[] = $id; } } $args2 = array( ‘post__in’ => array($post_IDs), ‘meta_query’ => array( … Read more

Post Title Not showing up

Add: $first_attachment = reset($attachments); $first_attachment_id = $first_attachment->ID; $first_attachment_title = $first_attachment->post_title; Below: $nbImg = count($attachments); Now you are able to return the link with: echo wp_get_attachment_link( $first_attachment_id, ” , true, false, $first_attachment_title ); If you need a sort of custom link markup, you can have a look at the related functions: http://codex.wordpress.org/Function_Reference/wp_get_attachment_link Edit: There is no … Read more