Order wp_query by calculated field
Using WP_Query, you can order the results by meta_value_num: $args = array ( ‘post_type’ => ‘clinica’, ‘meta_key’ => ‘distance_field_name’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ );
Using WP_Query, you can order the results by meta_value_num: $args = array ( ‘post_type’ => ‘clinica’, ‘meta_key’ => ‘distance_field_name’, ‘orderby’ => ‘meta_value_num’, ‘order’ => ‘DESC’ );
Depending on the way your script is recording max_price, it isn’t really a meta_key/meta_value on postmeta table. Did you try changin max_price clause to something like this? [‘max_price’] => [ ‘relation’ => ‘OR’, [ ‘key’ => ‘max_price’, ‘value’ => 11, ‘compare’ => ‘<=’, ], [ ‘key’ => ‘max_price’, ‘compare’ => ‘NOT EXISTS’, ], ],
This seems to work, but I would be interested in hearing from others if it’s the “correct” way to provide this sort of override. I’m assuming you’re visiting a category archive page, like http://www.example.com/category/computers/. // landing page = 188 // category = “computers” (#8) function custom_wpquery( $query ){ // the main query global $wp_the_query; if … Read more
I think you could get it working with category__and I remember trying a similar approach to yours and found out that I would get content that was either in platform and/or in review. But to get actually posts that where only on both, excluding posts that were just in one of them, this was my … Read more
Try this // Get categories $categories = wp_get_post_terms( get_the_ID(), ‘category’); // Check if there are any categories if( ! empty( $categories ) ) : // Get all posts within current category, but exclude current post $category_posts = new WP_Query( array( ‘cat’ => $categories[0]->term_id, ‘post__not_in’ => array( get_the_ID() ), ) ); // Check if there are … Read more
First, don’t hack core files (unless you intend to submit a patch 🙂 ). Second, what you are doing isn’t really checking to see if the title exactly matches the search string. What you are doing it checking to see if there is only one result. That doesn’t mean the title matches. Undo the core … Read more
Like Eugene mentioned in his answer you need to run a query for each tag. I would create a foreach loop that went through each tag then queried the latest 2 posts from each. $tags = get_tags(); foreach ( $tags as $tag ) { echo ‘<h3>’ .$tag->name. ‘</h3>’; $tag_query = new WP_Query( array( ‘tag_id’ => … Read more
REWORKED APPROACH The issue with the original answer is that although we pass post ID’s to post__in parameter, being on the author page, the main query removes all posts that does not belong to the author. We can pass an empty string to author_name via the pre_get_posts filter, but that inherintly breaks the query object, … Read more
You’re almost there — you just need to add the comparison to your meta query: $args = array( ‘post_type’ => ‘product’, ‘meta_query’ => array( array( ‘key’ => ‘artist’, ‘value’ => $artistID, ‘compare’ => ‘=’ ) ) ); https://codex.wordpress.org/Class_Reference/WP_Meta_Query Remember to filter $artistID before accepting it in your query!
I think you forgot about the inherit post status. The default one in WP_Query is publish. You should also use = instead of LIKE, to avoid using LIKE ‘%%’ in the SQL query. So try to add this: ‘post_status’ => ‘inherit’ and ‘compare’ => ‘=’ into your query arguments, to match the empty _wp_attachment_image_alt string … Read more