Custom URL parameters in template files

The global $wp_query object is not what you are looking for by the time you get to single.php. Instead use global $wp object. Try changing your code to this: global $wp; if (array_key_exists(‘myvar’, $wp->query_vars) && isset($wp->query_vars[‘myvar’])){ echo ‘custom variable recognized’; } print_r($wp->query_vars);

Conditional custom field query

I found this: http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query I have modified the date to retrieve the last 15 days. It’s untested, but should work. $expireDays=”15″; $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->posts.post_type=”post” AND $wpdb->posts.post_date >= ( CURDATE() – INTERVAL $expireDays DAY ) ORDER BY $wpdb->posts.post_date DESC “; $pageposts = $wpdb->get_results($querystr, … Read more

How to display specific posts with WP_Query?

Could be because you are passing an array of array try this: <?php $my_query = new WP_Query(); $my_query->query(array( ‘post__in’ => $curauth->user_favourite_post)); while ($my_query->have_posts()) : $my_query->the_post(); ?> <h3><a href=”https://wordpress.stackexchange.com/questions/27808/<?php the_permalink(); ?>”><?php the_title(); ?></a></h3> <?php endwhile; ?>

Ignoring a category in WP_Query still shows the links in next_post_link()?

You’ll have to exclude the category in your next_post_link and previous_post_link calls too, as it’s using the posts data, not your specific queries data, so, this should fix it: while ( $homepage->have_posts() ) : $homepage->the_post(); next_post_link( ‘&laquo; %link’, ‘%title’, false, ‘5’ ); previous_post_link( ‘%link &raquo;’, ‘%title’, false, ‘5’ ); endwhile; Where 5 is the excluded … Read more

WordPress pagination showing same posts on each page

You can replace the code with something like this <?php global $wp_query; $limit = get_option(‘posts_per_page’); $paged = (get_query_var(‘paged’)) ? get_query_var(‘paged’) : 1; query_posts(array(‘posts_per_page’=>$limit,’paged’=>$paged,’category_name’=>’albertsons, carrs, dominicks, genuardis, heb, kroger, pavillions, publix, randalls,safeway,shop-rite,tom-thumb,vons,whole-foods’)); /* you may want to uncomment the below two lines if you are using custom page template*/ //$wp_query->is_archive = true; //$wp_query->is_home = false; then … Read more

Tricky WP Query

For that kind of complex query, I’d recommend running two queries and then merging the results. First, get an array for: get all posts WHERE ( post_type=”post” AND category = 7 ) Then, get an array for: ( post_type=”case-studies” AND meta_key = ‘homeslide’ AND meta_value = 1 ) Then use array_merge() to combine the arrays … Read more