Post order by custom fields

That would be something like: query_posts( array( ‘cat’ => ’16’, ‘order’ => ‘ASC’, ‘orderby’ => ‘meta_value’, ‘meta_key’ => ‘time’, ) ); See WP_Query documentation in Codex for more information.

Fastest way to fetch posts across a multisite

yup it is fast, it would be even better for you to use the WP Transients API to cache your query for a short period. Basically: if($saved = get_site_transient(‘SOME_SORT_OF_ID’)){ echo $saved; } else { ob_start(); switch_to_blog(x); // x being the blog id your want to switch to // Do your quering and echoing here restore_current_blog(); … Read more

$post in wp_query?

$query = new WP_Query( $args ); while( $query->have_posts() ) { // this fills in the $post global with the next post from the query $query->the_post(); // we’re now ina classic wordpress loop, and can use all the usual stuff the_title(); the_content(); echo $post->post_content; } // lets clean up after ourself so else we might mess … Read more

Multiple loops breaking side bar

Since the sidebar was being deployed while inside the loop, the if ( have_posts() ) : was what was causing it to break. Here’s the fix: <div id=”FL-pest-libray-sidebar”> <?php $category_query_string = new WP_Query(array( ‘post_type’ => ‘page’ , ‘posts_per_page’ => ‘-1’ , ‘post_parent’ => ‘413’)); while ( $category_query_string->have_posts() ) : $category_query_string->the_post(); ?> <div <?php $catspacetitle = … Read more

Modifying WP URL handing code?

I ended up solving this with a little bit of code (in the form of a plugin): if(isset($_GET[‘state’]) OR isset($_GET[‘city’])) { $url = explode(“https://wordpress.stackexchange.com/”, $_SERVER[‘REQUEST_URI’]); $url = end($url); $_SERVER[‘REQUEST_URI’] = “https://wordpress.stackexchange.com/” . $url; } This code in essence removes the “/arizona/” or “/arizona/phoenix/” from the REQUEST_URI global variable and replaces it with “https://wordpress.stackexchange.com/”, which then … Read more

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