31 posts
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Envato Studio (Microlancer) Beta Tester
  • Referred between 1 and 9 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • India
TheMetroGuy says

Hi,

I have this code in a home.php to fetch the pages,

$args=array( 'post_type' => 'page', 'order' => 'ASC', 'orderby' => 'menu_order', 'post_status' => 'publish' ); $main_query = new WP_Query($args); if( have_posts() ) :

It is working fine everywhere except for one customer. It is not returning anything and always hitting the else block.

The WordPress version on which the site is running is 3.6. I already tested this on 3.6 in my preview sites and it is working fine there.

What might be the reason for WP_Query to not work?

1715 posts Don't Worry, Be Happy
  • Beta Tester
  • Grew a moustache for the Envato Movember competition
  • Elite Author
  • United States
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • Referred between 200 and 499 users
  • Most Wanted Bounty Winner
+2 more
FinalDestiny says

Check the 3rd party plugins, one of them may cause the problem.

332 posts
  • Exclusive Author
  • Sold between 5 000 and 10 000 dollars
  • Has been a member for 4-5 years
  • Europe
  • Envato Studio (Microlancer) Beta Tester
  • Bought between 1 and 9 items
  • Referred between 1 and 9 users
dekciw says

if($main_query->have_posts()) : $main_query->the_post();

31 posts
  • Exclusive Author
  • Sold between 10 000 and 50 000 dollars
  • Envato Studio (Microlancer) Beta Tester
  • Referred between 1 and 9 users
  • Bought between 10 and 49 items
  • Has been a member for 5-6 years
  • India
TheMetroGuy says

if($main_query->have_posts()) : $main_query->the_post();

Yes, this did the trick. Thanks a lot. :)

Any idea why it is working in other sites where I just have have_posts()? Just curious to know the details.

279 posts
  • Sold between 50 000 and 100 000 dollars
  • Exclusive Author
  • Has been a member for 1-2 years
  • Bought between 10 and 49 items
  • Referred between 10 and 49 users
PrimaThemes says

Any idea why it is working in other sites where I just have have_posts()? Just curious to know the details.

if you use query_posts, then:

query_posts($args); if( have_posts() ) : 

if you use WP_Query, then:

$main_query = new WP_Query($args); if( $main_query->have_posts() ) : 

that is the basic…

1715 posts Don't Worry, Be Happy
  • Beta Tester
  • Grew a moustache for the Envato Movember competition
  • Elite Author
  • United States
  • Sold between 250 000 and 1 000 000 dollars
  • Has been a member for 3-4 years
  • Referred between 200 and 499 users
  • Most Wanted Bounty Winner
+2 more
FinalDestiny says

Ah, I didn’t really check the syntax since he said it was working for all the other customers so I thought the problem was with that specific customer and not with his code :D

by
by
by
by
by
by