Mysql query and order meta value

While the WPDB class, or its global $wpdb instance are your friend when it comes to querying custom tables or WP core data that does not have a higher-level API, it is overkill to use it to query posts. Instead, read up on WP_Query. In your case, you’d use it like so: $args = array( … Read more

Optional Meta Query

All of the real work here is being done by $geoDataStore->getPostIDsOfInRange. That is where the search is done and that is what isn’t returning the results you want. WP_Query just pulls the specified post IDs. There is no reason you should have to abandon that part of the code, though you may want to add … Read more

is_tax() function not working as expected

If you take a look at this part of the WP_Query class: switch ( $tax_query[‘taxonomy’] ) { case ‘category’: $this->is_category = true; break; case ‘post_tag’: $this->is_tag = true; break; default: $this->is_tax = true; } then it looks like on category archive pages where is_category gives true then is_tax is false. So it looks like you … Read more

WP_Query Pagination on multiple-loop page breaks WP or doesn’t show up

Why can’t you write custom pagination? function theme_get_next_posts_link($query, $label = null, $max_page = 0) { global $paged; if(!$max_page) $max_page = $query->max_num_pages; if(!$paged) $paged = 1; $nextpage = intval($paged) + 1; if(null === $label) $label = “Older Posts”; if(!is_single() && $nextpage <= $max_page): $attr = apply_filters( ‘next_posts_link_attributes’, ” ); echo ‘<a class=”page-l” href=”‘ . next_posts( $max_page, … Read more

Query multiple meta values

You code is generating a broken meta_query. You code will produce something like this: array(1) { [“meta_query”]=> array(2) { [0]=> array(2) { [“relation”]=> string(2) “OR” [0]=> array(3) { [“key”]=> string(4) “test” [“value”]=> string(10) “test_value” [“compare”]=> string(4) “LIKE” } } } It should look like this: array(1) { [“meta_query”]=> array(2) { [“relation”]=> string(2) “OR” [0]=> array(3) … Read more

How do I run through a WordPress loop called from a filter function?

When using a custom query, in order to access the $post information, you need to reference post as a class variable the custom WP_Query. Since you constructed the query as: $hw_selectbox_query = new WP_Query($hw_selectbox_args); Then you would access the post variable of $hw_selectbox_query, like so: var_dump($hw_selectbox_query->post); This will give you the information you need / … Read more

Most commented last 24h, week, month, year and all time – posts_where

Where? The WP_Comment_Query class has the following filter for its clauses: $pieces = array( ‘fields’, ‘join’, ‘where’, ‘orderby’, ‘order’, ‘limits’, ‘groupby’ ); $clauses = apply_filters_ref_array( ‘comments_clauses’, array( compact( $pieces ), &$this ) ); That means you can hook into comments_clauses and filter the $clauses[‘where’] part. How? Since WP 3.7, we got a WP_Date_Query class. It … Read more