WP_Query sort by comment meta data

I solved my problem by adding a hook on the action wp_insert_comment. When my hook is called i calculate the average rating for each rating meta-tag of my comments. Then i add a meta tag to the post with the result I can use the post meta-tag to sort with wp-query

WP_Query based on URL parameters

Try like this $meta_query = array(‘relation’ => ‘AND’); if($queryGenre) { $query_genre = array( ‘key’ => ‘genre’, ‘value’ => $queryGenre, ‘compare’ => ‘=’, ) ; array_push($meta_query,$query_genre); } if($queryMood) { $query_mood = array( ‘key’ => ‘mood’, ‘value’ => $queryMood, ‘compare’ => ‘=’, ) ; array_push($meta_query,$query_mood); } and at the end do array_push($args,$meta_query);

Multiple endpoints in one URL

Not sure of the context for this, is it a custom post type or just a page? This might be something which you’re looking for – function add_lead_management_endpoints() { add_rewrite_rule( ‘manage-lead/lead_id/([0-9]{1,})/product_id/([0-9]{1,})’, ‘index.php?pagename=manage-lead&lead_id=$matches[1]&product_id=$matches[2]’, ‘top’ ); add_rewrite_tag( ‘%lead_id%’, ‘([^&]+)’ ); add_rewrite_tag( ‘%product_id%’, ‘([^&]+)’ ); } add_action( ‘init’, ‘add_lead_management_endpoints’ ); You’ll need to flush permalinks for this to … Read more

Get posts with condition on comment meta value

You can first try the following comment query: $comments = get_comments( [ ‘post_type’ => ‘projects’, ‘post_status’ => ‘publish’, ‘type’ => ‘message’, ‘date_query’ => [ [ ‘before’ => ‘5 days ago midnight’, ‘inclusive’ => true, ] ], ‘meta_query’ => [ [ ‘key’ => ‘foo’, // <– Adjust to your needs! ‘value’ => ‘bar’ // <– Adjust … Read more

WP_Query meta_query where meta value ends in space

Note sure how your structure is, but here’s one way, using RLIKE comparison and a space character class: array( ‘key’ => ‘_address_postcode’, ‘value’ => ‘^SC1[[:space:]]’, // Starts with ‘SC1 ‘ ‘compare’ => ‘RLIKE’ ) Maybe you should consider adjusting the meta values, as suggested by @cybmeta? But note that meta queries can be slow, so … Read more