Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

wp_reset_postdata Causing Validation Error WordPress

  • SOLVED

My code is below, it seems the placement of wp_resett_postdata is causing an XHTML validation error. How do I fix this while maintaining the CSS/HTML properties of my unordered list?

<ul class="feature-sec">
<?php
$args = array(
'post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => -1,
'post_parent' => $post->ID,
);
$query = new WP_Query($args);
while ($query->have_posts()) {
$query->the_post(); ?>
<li>
<a href="<?php the_permalink() ?>"><?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-features' ); } ?></a>
<div class="inner-feature">
<a class="name" href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php the_excerpt(); ?>
<?php } wp_reset_postdata(); ?>
</div>
</li>
</ul>

Answers (1)

2014-04-01

Luis Abarca answers:

<strong>[FIX] Sorry, i forgot to include global $post on the function get_custom_pages().</strong>

Separate things first to make it more readable.

<strong>functions.php</strong>

function get_custom_pages()
{
global $post;

$args = array(
'post_type' => 'page',
'orderby' => 'menu_order',
'order' => 'ASC',
'post_status' => 'publish',
'posts_per_page' => -1,
'post_parent' => $post->ID,
);

return new WP_Query($args);
}


<strong>// your template file</strong>

<?php
// get the pages of the page parent x
$query = get_custom_pages();
?>
<?php if ($query->have_posts()): ?>
<ul class="feature-sec">
<?php while ($query->have_posts()) : $query->the_post() ?>
<li>
<a href="<?php the_permalink() ?>"><?php if (has_post_thumbnail()) the_post_thumbnail( 'thmb-features' ) ?></a>
<div class="inner-feature">
<a class="name" href="<?php the_permalink() ?>"><?php the_title() ?></a>
<?php the_excerpt() ?>
</div>
</li>
<?php endwhile ?>
</ul>
<?php endif ?>
<?php wp_reset_postdata() ?>


siouxfan45 comments:

In seems this code is close, BUT it is pulling ALL child pages. It should only pull children of the current page. How do I fix this? Thanks!