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?

1959 posts Don't Worry, Be Happy
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has referred 200+ members
+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
+2 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…

1959 posts Don't Worry, Be Happy
  • Sells items exclusively on Envato Market
  • Elite Author: Sold more than $75,000 on Envato Market
  • Made it to the Authors' Hall of Fame
  • Has referred 200+ members
+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

Helpful Information

  • Please read our community guidelines. Self promotion and discussion of piracy is not allowed.
  • Open a support ticket if you would like specific help with your account, deposits or purchases.
  • Item Support by authors is optional and may vary. Please see the Support tab on each item page.

Most of all, enjoy your time here. Thank you for being a valued Envato community member.

Post Reply

Format your entry with some basic HTML. Read the Full Details, or here is a refresher:

<strong></strong> to make things bold
<em></em> to emphasize
<ul><li> or <ol><li> to make lists
<h3> or <h4> to make headings
<pre></pre> for code blocks
<code></code> for a few words of code
<a></a> for links
<img> to paste in an image (it'll need to be hosted somewhere else though)
<blockquote></blockquote> to quote somebody

:grin: :shocked: :cry: Complete List of Smiley Codes

by
by
by
by
by
by