Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I've been given some code to tidy up and edit a bit and the client wants to organize a custom post type named "plans" alphabetically.

It's not a straight forward query and I've never come across anything like this before, any ideas?

<?php $planIDs = get_post_meta($post->ID, '_lm_comm_plans', false); ?>
<?php foreach ($planIDs as $planID) : ?>
    <?php $pdfID = get_post_meta($planID, '_lm_plan_pdf', true); ?>
        <?php $pdfURL = wp_get_attachment_url($pdfID); ?>
            <?php $planTitle = get_the_title($planID); ?>
                <li class="plan"><!-- content here --></li>
<?php endforeach; ?>
share|improve this question
    
where does $planIDs come from? –  Milo Jan 6 '12 at 19:40
    
My mistake, I missed a line out. Edited. –  Dean Elliott Jan 6 '12 at 19:52

1 Answer 1

up vote 0 down vote accepted

You'll need to run through get_posts() to apply the order by handling.

$planIDs = get_post_meta( $post->ID, '_lm_comm_plans', false );
foreach( get_posts( array( 'post__in' => $planIDs, 'orderby' => 'name', 'order' => 'ASC', 'post_type' => 'plans' ) ) as $plan ) {
    $pdfID = get_post_meta( $planID, '_lm_plan_pdf', true );
    $pdfURL = wp_get_attachment_url( $pdfID );
    $planTitle = get_the_title( $planID );
    ?>
    <li class="plan"><!-- content here --></li>
    <?php
}
share|improve this answer
    
That didn't seem to work, the page is completely blank. –  Dean Elliott Jan 9 '12 at 9:58
    
Dean, Sorry, I didn't pay attention the fact that the related plans were another post type. You just need to make sure the post type is set in the query. I've updated the code for this. –  prettyboymp Jan 9 '12 at 13:27

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.