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

How to get all images and their thumbnails from wp media library

Here’s what you can do. Get a list of all available thumbnail sizes Query all the attachments For each attachment size, get it’s URL and save it into the array Let’s change your code into this: function get_images_highcompress_data() { $args = array( ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image/jpeg,image/jpg,image/png’, ‘post_status’ => ‘inherit’, ‘posts_per_page’ => -1, ‘orderby’ … Read more

WP_Query to loop a Custom Field, Custom Post Types do not show

There’s a missing opening quote and closing bracket on this line: <i class=<?php the_field(‘course_feature_icon’); ?>”</i> Needs to be: <i class=”<?php the_field(‘course_feature_icon’); ?>”></i> That’s all that’s wrong with your code. It should then work assuming: You have a custom field, course_feature_icon, whose value is a valid CSS class. You have the necessary CSS to add an … Read more

Group posts by custom field

You’re close. You have: foreach (get_child_pages(wp_get_post_parent_id(get_the_ID())) as $s) { echo ‘<li><a href=”‘ . get_the_permalink($s->ID) . ‘”>’ . get_the_title($s->ID) . ‘</a></li>’; } We need to add a layer above that to show the two lists. However we can’t assume that the posts of one type will all come out together (i.e. all of one category, then … Read more

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