Help with MySQL to $WPDB query

http://codex.wordpress.org/Class_Reference/wpdb query returns the number of affected rows. Instead use get_results, which returns all the rows specified by the query. You can use the second parameter to specify how these results will be returned, either as objects or as an array etc When dealing with sql, you should deal only with wpdb, there is very … Read more

Display posts with a start OR end date later than current date

Edit: I believe my comments below are still valid, but I suspect part of the problem is the ‘relation’ => ‘OR’, This should be ‘AND’ (it’s default value,so it can be removed) to ensure that it only returns posts which satisfy both conditions. Currently it will return events that start, or end, after yesterday. In … Read more

Only show upcoming event or current events

your are comparing time against wrong time string: change: ‘meta-value’ => date(‘Y-m-d’, strtotime(‘-6 hours’)), //value of “order-date” to this ‘value’ => date(‘m-d-Y’, strtotime(‘-6 hours’)), //value of “order-date” because your time string is in m-d-Y format and you are check against Y-m-d which is wrong. NOTE if above trick doesn’t work then i suggest you to … Read more

Query Custom Post Type posts by Keyword/url slug

You can use the name parameter in your arguments ex: <?php $args = array( ‘post_type’ => ‘product’, ‘posts_per_page’ => 12, ‘name’ => ‘slug’ ); but this will only match the post with that same slug.

List all posts from past week grouped by sub-category

I would recommend that you use WP_Query for this one: $categories = get_categories( ‘child_of=83’ ); foreach ( $categories as $category ) { echo ‘<h3>’ . $category -> name . ‘</h3>’; echo ‘<ul>’; // create a WP_Query that retreives all posts from the specified // category which is older then 1 week $args = array( ‘cat’ … Read more

Alter a specific query on WordPress

You might be able to use the query filter hook See this WPSE answer Basically, you can do something like: add_filter( ‘query’, ‘your_filter_function’ ); function your_filter_function($query_sql) { // do something to $query_sql return $query_sql; } This will get called for every query, so you’ll need to test $query_sql to make sure it’s the query you … Read more

Temporarily storing main search result

The way I see it, you have three options: Store the global search data in $_SESSION Store the global data in a transient Run the query twice, with & without the post type filter I tried storing the array in a global variable and as soon as the page refreshes with the refined search results, … Read more