This is so weird.
I’ve written a widget to pull a single post from a custom post type in the sidebar (a “testimonial”) and display it randomly on page reload/page change. it works fine – *except* on the author page.
I removed *everything* from my author template file to see if something in that code is conflicting, but it still makes the widget not work, which makes me thing the fact that it’s an author page alone is what’s interfering.
My query is pretty standard:
$test = new WP_Query(array('post_type' => 'testimonial', 'post_status' => 'publish', 'posts_per_page' => '1', 'orderby' => 'rand')); if($test->have_posts()) : while($test->have_posts()) : $test->the_post(); //standard output endwhile; endif; wp_reset_query();
But when I return the query request, it’s not the same on the author page as it is on all the other pages. On all the other pages (where it’s working) the request (
print_r($test->request);looks like this:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = 'testimonial' AND (wp_posts.post_status = 'publish') ORDER BY RAND() DESC LIMIT 0, 1
but on the author pages, it looks like this:
SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts INNER JOIN wp_term_relationships ON (wp_posts.ID = wp_term_relationships.object_id) INNER JOIN wp_term_taxonomy ON ( wp_term_relationships.term_taxonomy_id = wp_term_taxonomy.term_taxonomy_id ) WHERE 1=1 AND wp_posts.post_type = 'testimonial' AND (wp_posts.post_status = 'publish') GROUP BY wp_posts.ID ORDER BY RAND() DESC LIMIT 0, 1
The author page request ends up returning nothing as a result of the query. Since the request is the only thing that’s different, I can only assume that it’s the reason why it’s returning empty results.
What is it about the author page that makes this happen? Is there any way around it? I’m at a loss here – I’ve never, ever seen this happen before!
- The topic ‘getting different Request on author pages with wp_query_posts()’ is closed to new replies.