898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
Gareth_Gillman says

I am building a “one-page” theme and a little stuck… It was working before I upgraded to 3.9 (worked on 3.8)

$args = array(
    'sort_order' => 'ASC',
    'sort_column' => 'menu_order',
    'hierarchical' => 1,
    'post_type' => 'page',
    'post_status' => 'publish',
 );
 $pages = get_pages($args);
 foreach ($pages as $page_data) {
  $content = apply_filters('the_content', $page_data->post_content);
 echo $content;
}

It’s displaying the first page but not the rest so it’s breaking the sequence but there are no WP debug / php errors and I can’t see why it should break!

Any ideas?

75 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
ThemesHolic says

Try with query_posts($args).

Remember to add wp_reset_query(); at the end of the cycle.

898 posts
  • Has been part of the Envato Community for over 4 years
  • Has referred 1+ members
  • Has been a beta tester for an Envato feature
  • Has collected 10+ items on Envato Market
+4 more
Gareth_Gillman says

Try with query_posts($args). Remember to add wp_reset_query(); at the end of the cycle.

No change, it’s wierd as as it worked before

Found the issue, for some reason the theme started using another template file :|

1509 posts
  • Has referred 1+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Made it to the Authors' Hall of Fame
+2 more
OriginalEXE says

Try with query_posts($args). Remember to add wp_reset_query(); at the end of the cycle.

Never use query_posts() :)

75 posts
  • Has referred 10+ members
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Sells items exclusively on Envato Market
+2 more
ThemesHolic says


Try with query_posts($args). Remember to add wp_reset_query(); at the end of the cycle.
Never use query_posts() :)
The exact use-case that query_posts() was designed for: using a custom page template as an archive of posts, so it’s perfect for a custom one page template :)
3437 posts
  • Has sold $5,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Located in United States
  • Has been part of the Envato Community for over 4 years
+1 more
organicbee says



Try with query_posts($args). Remember to add wp_reset_query(); at the end of the cycle.
Never use query_posts() :)
The exact use-case that query_posts() was designed for: using a custom page template as an archive of posts, so it’s perfect for a custom one page template :)
http://codex.wordpress.org/Function_Reference/query_posts nope.
Note: This function isn’t meant to be used by plugins or themes. As explained later, there are better, more performant options to alter the main query. query_posts() is overly simplistic and problematic way to modify main query of a page by replacing it with new instance of the query. It is inefficient (re-runs SQL queries) and will outright fail in some circumstances (especially often when dealing with posts pagination). Any modern WP code should use more reliable methods, like making use of pre_get_posts hook, for this purpose.

use http://codex.wordpress.org/Class_Reference/WP_Query

386 posts
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
+3 more
kaaz says
try this
$pages = array();
$pages_obj = get_pages( 'sort_column=post_parent,menu_order' );  

foreach( $pages_obj as $page ){
    $pages[ $page->ID ] = $page->post_name; 
}

//all pages in array
$pages
386 posts
  • Has sold $40,000+ on Envato Market
  • Has been a beta tester for an Envato feature
  • Has been part of the Envato Community for over 4 years
  • Sells items exclusively on Envato Market
+3 more
kaaz says
custom loop
    $loop = new WP_Query( array( 'post_type' => 'page', 'posts_per_page' => -1 ));

    if( $loop->have_posts() ) :

        while( $loop->have_posts() ) : $loop->the_post();

            the_content();

        endwhile;

        wp_reset_query();

    else :

       echo '<p>Sorry, no pages were found.</p>';

    endif;
293 posts
  • Has sold $10,000+ on Envato Market
  • Has collected 10+ items on Envato Market
  • Has referred 1+ members
  • Helped protect Envato Market against copyright violations
+2 more
juarathemes says

WP_Query() is your best friend mate ;)

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