0

I was developing a site on localhost, and just transferred everything over to the live site. The queries are the exact same between the live and staging sites, But the query is not working on my live site.

I'm trying to query a random post out of a category to display in my footer. It's a very simple query so I'm not sure why it's not working. It's just showing me the same post every page reload.

Localhost, it works as expected and shows a random post from that post type.

<?php $recipesloop = new WP_Query( array( 'post_type' => 'recipes', 'posts_per_page' => '1', 'orderby' => 'rand') ); ?>

This is what is returned:

     WP_Query Object (
[query_vars] => Array (
[post_type] => recipes
[posts_per_page] => 1
[orderby] => rand
[error] =>
[m] =>
[p] => 0
[post_parent] =>
[subpost] =>
[subpost_id] =>
[attachment] =>
[attachment_id] => 0
[name] =>
[static] =>
[pagename] =>
[page_id] => 0
[second] =>
[minute] =>
[hour] =>
[day] => 0
[monthnum] => 0
[year] => 0
[w] => 0
[category_name] =>
[tag] =>
[cat] =>
[tag_id] =>
[author] =>
[author_name] =>
[feed] =>
[tb] =>
[paged] => 0
[comments_popup] =>
[meta_key] =>
[meta_value] =>
[preview] =>
[s] =>
[sentence] =>
[fields] =>
[menu_order] =>
[category__in] => Array (
)
[category__not_in] => Array (
)
[category__and] => Array (
)
[post__in] => Array (
)
[post__not_in] => Array (
)
[tag__in] => Array (
)
[tag__not_in] => Array (
)
[tag__and] => Array (
)
[tag_slug__in] => Array (
)
[tag_slug__and] => Array (
)
[post_parent__in] => Array (
)
[post_parent__not_in] => Array (
)
[author__in] => Array (
)
[author__not_in] => Array (
)
[ignore_sticky_posts] =>
[suppress_filters] =>
[cache_results] =>
[update_post_term_cache] => 1
[update_post_meta_cache] => 1
[nopaging] =>
[comments_per_page] => 50
[no_found_rows] =>
[order] => DESC
)
[tax_query] => WP_Tax_Query Object (
[queries] => Array (
)
[relation] => AND
)
[meta_query] => WP_Meta_Query Object (
[queries] => Array (
)
[relation] =>
)
[date_query] =>
[post_count] => 1
[current_post] => -1
[in_the_loop] =>
[comment_count] => 0
[current_comment] => -1
[found_posts] => 10
[max_num_pages] => 10
[max_num_comment_pages] => 0
[is_single] =>
[is_preview] =>
[is_page] =>
[is_archive] => 1
[is_date] =>
[is_year] =>
[is_month] =>
[is_day] =>
[is_time] =>
[is_author] =>
[is_category] =>
[is_tag] =>
[is_tax] =>
[is_search] =>
[is_feed] =>
[is_comment_feed] =>
[is_trackback] =>
[is_home] =>
[is_404] =>
[is_comments_popup] =>
[is_paged] =>
[is_admin] =>
[is_attachment] =>
[is_singular] =>
[is_robots] =>
[is_posts_page] =>
[is_post_type_archive] => 1
[query_vars_hash] => 79b1d4c4dd907be2bdf06d3b2e4bd2f8
[query_vars_changed] =>
[thumbnails_cached] =>
[stopwords:WP_Query:private] =>
[query] => Array (
[post_type] => recipes
[posts_per_page] => 1
[orderby] => rand
)
[request] => SELECT SQL_CALC_FOUND_ROWS wp_posts.ID FROM wp_posts WHERE 1=1 AND wp_posts.post_type = \'recipes\' AND (
wp_posts.post_status = \'publish\' OR wp_posts.post_status = \'private\'
) ORDER BY RAND(
) DESC LIMIT 0, 1
[posts] => Array (
[0] => WP_Post Object (
[ID] => 228
[post_author] => 2
[post_date] => 2014-03-04 11:00:59
[post_date_gmt] => 2014-03-04 16:00:59
[post_content] => Combine flour, salt, pepper and cayenne in a saucepan; gradually add chicken broth and skim milk, stirring with a wire whisk until smooth. Place over medium heat and cook, stirring constantly, until thickened. Add mustard and lemon juice. Allow to cool. Heat margarine and oil in a skillet. Add chicken pieces, green onions and garlic. Sauté until chicken is just firm and cooked through, about 10 minutes. Prepare pasta according to package directions and drain. Combine sauce, chicken and pasta mixture. Put into a 2 ½-quart casserole dish. Sprinkle top with almonds, chopped chives and paprika (
if using
). Bake at 375° for 10 minutes or until heated through.
[post_title] => Zingy Lemon Chicken Pasta
[post_excerpt] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => zingy-lemon-chicken-pasta
[to_ping] =>
[pinged] =>
[post_modified] => 2014-03-07 15:07:38
[post_modified_gmt] => 2014-03-07 20:07:38
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://baltimarket.wpengine.com/?post_type=recipes&p=228
[menu_order] => 0
[post_type] => recipes
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
[post] => WP_Post Object (
[ID] => 228
[post_author] => 2
[post_date] => 2014-03-04 11:00:59
[post_date_gmt] => 2014-03-04 16:00:59
[post_content] => Combine flour, salt, pepper and cayenne in a saucepan; gradually add chicken broth and skim milk, stirring with a wire whisk until smooth. Place over medium heat and cook, stirring constantly, until thickened. Add mustard and lemon juice. Allow to cool. Heat margarine and oil in a skillet. Add chicken pieces, green onions and garlic. Sauté until chicken is just firm and cooked through, about 10 minutes. Prepare pasta according to package directions and drain. Combine sauce, chicken and pasta mixture. Put into a 2 ½-quart casserole dish. Sprinkle top with almonds, chopped chives and paprika (
if using
). Bake at 375° for 10 minutes or until heated through.
[post_title] => Zingy Lemon Chicken Pasta
[post_excerpt] => Pellentesque habitant morbi tristique senectus et netus et malesuada fames ac turpis egestas.
[post_status] => publish
[comment_status] => closed
[ping_status] => closed
[post_password] =>
[post_name] => zingy-lemon-chicken-pasta
[to_ping] =>
[pinged] =>
[post_modified] => 2014-03-07 15:07:38
[post_modified_gmt] => 2014-03-07 20:07:38
[post_content_filtered] =>
[post_parent] => 0
[guid] => http://baltimarket.wpengine.com/?post_type=recipes&p=228
[menu_order] => 0
[post_type] => recipes
[post_mime_type] =>
[comment_count] => 0
[filter] => raw
)
)
4
  • what does $recipesloop->request look like?
    – Milo
    Mar 11 '14 at 22:27
  • Let me do a var_dump, give me a second. I can see that it returns all 10 posts as expected tho.
    – EHerman
    Mar 11 '14 at 22:28
  • Looks to me like the post data is all there
    – EHerman
    Mar 11 '14 at 22:33
  • would love some help. turned on wp_debug, nothing.
    – EHerman
    Mar 11 '14 at 22:52
1

To any one else facing this issue....

I assume your using WP Engine.

I only say this because it turns out WP Engine turns off the rand parameter by default. Go to your wp engine dashboard settings, scroll down and enable the random functionality.

What a pain.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.