Display upcoming events in the next 30 days by querying posts with timestamp in custom meta

I recently did exactly the same, you’ll have to use custom query: $date = time()-86400; /* today */ $querystr = ” SELECT $wpdb->posts.* FROM $wpdb->posts, $wpdb->postmeta WHERE $wpdb->posts.ID = $wpdb->postmeta.post_id AND $wpdb->posts.post_status=”publish” AND $wpdb->postmeta.meta_key = ‘event_date’ AND $wpdb->postmeta.meta_value > ” . $date . ” ORDER BY $wpdb->postmeta.meta_value ASC “; $pageposts = $wpdb->get_results($querystr, OBJECT); foreach ($pageposts … Read more

Magazine style frontpage with multiple categories/loops and no duplicate posts

I wrote a class specifically for passing data between widgets classes using static variables and it will work for your use case as well. Grab the class here. The way you would use this is as follows for each custom loop: $exclude_ids = IntermediaryData::get(); //Retrieve previous exclude IDs $args[‘post__not_in’] = $exclude_ids; //new WP_Query($args); Custom loop … Read more

How to get pages of parent (non-recursive)?

Assuming that, by “HOME_ID”, you are referring to the static Page used to display the Site Front Page, then you want to use get_option( ‘front_page’ ) to get the ID for this page: <?php $menu_wp_query_args = array( ‘post_type’ => ‘page’, ‘post_parent’ => get_option( ‘front_page’ ), ‘orderby’ => ‘menu_order’ ); $new_wp_query = new WP_Query( $new_wp_query_args ); … Read more

What’s wrong with this wpdb query?

Try this, it worked for me: global $wpdb; $terms = $wpdb->get_col( $wpdb->prepare( “SELECT name FROM {$wpdb->terms} WHERE term_group = %d ORDER BY name ASC”, primary_tag_id )); What you are after is $wpdb->terms not $wpdb->wp_terms

Help with Wp Query

$authors = get_users( array( ‘fields’ => ‘ID’, ‘role’ => ‘your_role’ )); $my_query = new WP_Query( array( ‘post_type’ => ‘your_post_type’, ‘author’ => implode( ‘,’, $authors ) ));

Modify output of custom loop using WP_query

$args = array( ‘posts_per_page’ => -1, ‘post_type’ => ‘hotwives’, ‘post_status’ => ‘publish’, ‘tax_query’ => array( array( ‘taxonomy’ => ‘category’, ‘field’ => ‘slug’, ‘terms’ => ‘slider’, ‘operator’ => ‘NOT IN’ ) ) ); Use that as the args for your WP_Query and you should get posts that aren’t in the category taxonomy. It also has the … Read more

Using WP_Query with multiple loops on one page in search.php

Alright, I just whipped something up, this should do it, but it’s untested. <?php $premium_args = array( ‘post_status’ => ‘publish’, ‘meta_query’ => array( array( ‘key’ => ‘seek_premium’, ‘value’ => ‘yes’ ) ) ); $premium_posts = new WP_Query( $premium_args ); ?> <?php foreach( $premium_posts as $p ) : ?> Your output here <?php endforeach; ?> <?php … Read more

Admin: Custom Query Returning Permissions Error

I think the problem is that by just appending ?deleteUser=XX you get an ‘illegal’ url, for example: http://localhost/wordpress/wp-admin/edit.php?post_type=type&page=mypage?deleteUser=xxx Instead, use WordPress’ add_query_arg: $url = $_SERVER[‘REQUEST_URI’]; $url = add_query_arg(‘test’,’val’,$url); which gives: http://localhost/wordpress/wp-admin/edit.php?post_type=type&page=mypage&deleteUser=xxx Personally, I wouldn’t use $_SERVER[‘REQUEST_URI’]; and instead hard-code the url of the page using admin_url. Also, see @Joshua comments on using the WordPress in-built … Read more

How to sort by most watched in X days/months

Not sure exactly what you mean by “x days or months”, but I’m assuming you want to set a time interval for the posts that you are querying. I would recommend that you take a look at the “Time Parameters” section in the Codex article on WP_Query. It does an excellent job explain how to … Read more