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 trying to order the custom fields alphabetically, but I can't get the ordered list I want... this is the code I'm using:

<?php 
        $vMarca = get_field('tienda_marcas'  , false, false);
        $post_objects = get_posts(array(
            'post__in'   => $vMarca,
            'order'   => 'ASC'  ,
            'orderby'   => 'title'  
        ));

        if($vMarca)
        {
            echo '<ul>' ;
            foreach($vMarca as $post_objects)
            {
                echo '<li>'  . $post_objects . '</li>' ;
            }
            echo '</ul>' ;
        }

        ?>

I need the custom fields to be ordered alphabetically.

share|improve this question
    
So What's output ? –  revo Mar 18 '13 at 18:42
    
You are using the $post_objects variable in 2 different contexts here. Also, what is get_field? That's not a native WP function. –  vancoder Mar 18 '13 at 18:52
    
Hey, thanks for your answers! Sorry if i didn't specify the problem... i'm using Advanced Custom Fields and the output is this: grab.by/kOz8... As you can see, the item "Otra Marca" is at the end, but it should be listed alphabetically... that is the problem –  Juan Pablo Contreras Mar 18 '13 at 19:14
    
also, "get_field" it's from Advanced Custom Fields –  Juan Pablo Contreras Mar 18 '13 at 19:18

1 Answer 1

It looks like you're trying to output the wrong stuff. You've ordered the $post_objects, not the $vMarca. Try using the $post_objects variable for your if and foreach statements thus:

<?php 
    $vMarca = get_field('tienda_marcas'  , false, false);
    $post_objects = get_posts(array(
        'post__in'   => $vMarca,
        'order'   => 'ASC'  ,
        'orderby'   => 'title'  
    ));

    if($post_objects)
    {
        echo '<ul>' ;
        foreach($post_objects as $post)
        {
            setup_postdata($post); ?>
            <li><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></li>
            <?php the_content(); ?>
        }
        echo '</ul>' ;

    ?>
share|improve this answer
    
Great Answer! but i haven't been clear with the problem. I assume that i'm calling the wrong stuff. Let me rephrase it: i have installed Advanced Custom Field and i'm calling custom fields in a post in this way: grab.by/kOGO, which outpost this way: grab.by/kOHi. As you can see, the resultant list is not ordered alphabetically, that is my question. –  Juan Pablo Contreras Mar 18 '13 at 20:17
    
Right - I believe I understand you. What I'm saying is that it looks like, since you were looping through $vMarca which was unordered, you would want to switch to looping through $post_objects which you had ordered. Did you try my version? –  jfacemyer Mar 19 '13 at 19:56
    
Any progress, @JuanPabloContreras? –  jfacemyer Mar 21 '13 at 13:54

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.