My code lists the child pages ordered by post title, pulling through the first image attachment of the child post as the thumbnail.
The child pages contain custom fields created using the Magic Fields plugin.
Can anyone help me adjust my code so that I can have my pages listed in descending order of a custom field called 'price'?
This is my code:
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<div class="page" id="post-<?php the_ID(); ?>">
<div class="pagecontent">
<?php $child_pages = $wpdb->get_results("SELECT * FROM $wpdb->posts WHERE post_parent = ".$post->ID." AND post_type = 'page' ORDER BY post_title", 'OBJECT'); ?>
<?php if ( $child_pages ) : foreach ( $child_pages as $pageChild ) : setup_postdata( $pageChild ); ?>
<div class="grid"><a href="<?php echo get_permalink($pageChild->ID); ?>" alt="<?php echo $pageChild->post_title; ?>" title="<?php echo $pageChild->post_title; ?>">
<?php $attachments = get_children( array(
'post_parent' => $pageChild->ID,
'post_type' => 'attachment',
'numberposts' => 1, // show all -1
'post_status' => 'inherit',
'post_mime_type' => 'image',
'order' => 'ASC',
'orderby' => 'menu_order ASC'
) );
foreach ( $attachments as $attachment_id => $attachment ) {
echo wp_get_attachment_image( $attachment_id, 'medium' );
} ?>
</a>
<h1><a href="<?php echo get_permalink($pageChild->ID); ?>" title="<?php echo $pageChild->post_title; ?>"><?php echo $pageChild->post_title; ?></a></h1>
</div>
<?php endforeach; endif; ?>
</div>
</div>
<?php endwhile; endif; ?>
I would appreciate any help!
Thank you.