1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 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?

89 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Copyright Ninja
+3 more
ThemesHolic
says

Try with query_posts($args).

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

1096 posts
  • 5 Years of Membership
  • Affiliate Level 1
  • Beta Tester
  • Collector Level 2
+5 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 :|

1565 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Featured Author
+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() :)

89 posts
  • Affiliate Level 2
  • Author Level 5
  • Collector Level 2
  • Copyright Ninja
+3 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 :)
3439 posts
  • Author Level 4
  • Collector Level 2
  • Community Superstar
  • United States
+2 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

408 posts
  • Most Wanted Winner
  • Author Level 6
  • Exclusive Author
  • Beta Tester
+2 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
408 posts
  • Most Wanted Winner
  • Author Level 6
  • Exclusive Author
  • Beta Tester
+2 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;
485 posts
  • Author Level 6
  • Collector Level 3
  • Exclusive Author
  • Copyright Ninja
+3 more
juarathemes
says

WP_Query() is your best friend mate ;)

by
by
by
by
by
by