35 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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?

1792 posts Don't Worry, Be Happy
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Located in United States
  • Made it to the Authors' Hall of Fame
+8 more
FinalDestiny says

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

332 posts
  • Has referred 1+ members
  • Has sold $5,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 1+ items on Envato Market
+3 more
dekciw says

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

35 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+3 more
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.

280 posts
  • Has referred 10+ members
  • Has sold $40,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+1 more
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…

1792 posts Don't Worry, Be Happy
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Located in United States
  • Made it to the Authors' Hall of Fame
+8 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