SQL query to select posts from multiple categories

I would use the built in API like Rarst mentioned. You could do something like this: $just_seven = new WP_Query( array( ‘category__in’ => array( 7 ), ‘category__not_in’ => array( 10 ) ) ); You would then have those items in $just_seven->posts. However, if you MUST use a direct SQL statement, I’d suggest using INNER JOIN … Read more

Exclude featured image and custom field from this get_attachment query

The asker refused to post his solution as answer, so I took the liberty to get this question out of our growing Unanswered Questions list … <?php $logo = get_post_meta($post->ID, ‘_lm_comm_logo’, true); $map = get_post_meta($post->ID, ‘_lm_comm_map’, true); $args = array( ‘numberposts’ => -1, ‘orderby’ => ‘menu_order’, ‘order’ => ‘ASC’, ‘post_type’ => ‘attachment’, ‘post_mime_type’ => ‘image’, … Read more

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.

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