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.

an update on this: I managed to change from 'orderby'=>'title' to 'orderby'=>'date'as suggested. This almost made the order perfect except one clarinet that falls out of the order and is placed in the wrong place. As far as I know understand, this could be an error in the programming since everything else works in the right order?

See: http://www.dnbe.no/ensemblet/ and second from top left: Eirik Jordal , klarinett, should be further down.

Anybody knows?

Thanks, Martin G, Norway.

The whole code:

    <?php get_featured_posts('musicians'); ?>

    <section id="primary">

        <div id="content" role="main">

            <header class="page-header">
                <h2 class="page-title">Musikerne i Det Norske Bl&aring;seensemble</h2>
            </header>   

            <div class="musicians-archive">
                <?php
                    global $post;
                    $posts = get_posts(array(
                        'post_type'=>'dnbe_musician',
                        'post_status'=>'publish',
                        'orderby'=>'date',
                        'order'=>'ASC',
                        'numberposts'=>-1
                    ));
                    if($posts){
                        $c = 0;
                        $al = count($posts);
                        $r = round($al / 3);
                        $id = 1;
                        foreach($posts as $post){ 
                            $post_custom = get_post_custom($post->ID);
                            if($c == 0){ ?>
                                <div class="dnbe_musician_column">
                            <?php 
                            }
                            if($post_custom['dnbe_musician_instrument'][0] != ''){
                                $instrument = ', '.$post_custom['dnbe_musician_instrument'][0];
                            } else {
                                $instrument = '';
                            }
                            ?>
                            <div class="dnbe_musician" musician_id="<?php echo $id; ?>"><h2 class="entry-title"><a href="<?php echo get_permalink($post->ID); ?>"><?php echo $post->post_title.$instrument; ?></a></h2></div>
                            <?php
                            $c++;
                            if($c == $r+1){ 
                                $c = 0; ?>
                                </div>
                            <?php } 
                            ?>
                        <?php $id++;
                        }
                    }
                    wp_reset_query();
                ?>
            </div>      

        </div><!-- #content -->
    </section><!-- #primary -->

Thanks in advance, Martin G, Norway


I¨m trying to stack the names of our musicians in the right, non-alphabetical, order on the web page. In the cms the order is right, but on the web page the names are listed alphabetically.

The homepage is made by a company, but I now try to edit some parts myself.

How do I fix this inside cms?

Check out the list here: http://www.dnbe.no/ensemblet/

The code is:

    <?php get_featured_posts('musicians'); ?>

    <section id="primary">

        <div id="content" role="main">

            <header class="page-header">
                <h2 class="page-title">Musikerne i Det Norske Bl&aring;seensemble</h2>
            </header>   

            <div class="musicians-archive">
                <?php
                    global $post;
                    $posts = get_posts(array(
                        'post_type'=>'dnbe_musician',
                        'post_status'=>'publish',
                        'orderby'=>'title',
                        'order'=>'ASC',
share|improve this question

1 Answer 1

You have what looks to be a custom theme and the theme probably has a template of some sort to handle the ensemblet section. In the code for that section (which might be accessible through Appearance -> Editor -> Name of the file which holds this template), there should be a loop of some kind to pull the names from the database. Try pasting the code from that in to your question to get a better response.

In general, if your theme was developed using the Wordpress framework, and it uses a custom post type for the ensemblet entries, it probably has a loop similar to this:

$wpdb->query("SELECT ID,post_name FROM {$wpdb->prefix}posts WHERE post_type='ensemblet' ORDER BY post_title;");

If you see something like this, replace the 'ORDER BY post_title' with 'ORDER BY ID' or 'ORDER BY post_date'.

If the loop is more like this:

<?php /* Start the Loop */ ?>
<?php while ( have_posts() ) : the_post(); ?>
... some code ...
<?php endwhile; ?>

Then add in the following line above the while statement: query_posts('orderby=date');

If there already is a query_posts call, you will have to edit that line to include the orderby=date which could be represented two ways:

A string with an ampersand (&) before it:

query_posts('otherstuff=something&orderby=date');

Or using an array with an additional line added (make sure to add a comma to the next to last line):

$args = array(
'otherstuff' => 'something',
'orderby' => 'date'
);
query_posts($args);
share|improve this answer
    
You can also use $wpdb->posts instead. Oh and afaik you need to use prepare to avoid SQL injections. –  kaiser Jan 5 '12 at 17:04
1  
There is no possible way the query could be injected in to, it is a closed query with no outside variables (besides the $wpdb object), so using a prepare statement would be unnecessary and wasteful. It doesn't matter anyway in this case as I was providing an example of what to look for, not code to be used. Good point on the $wpdb->posts, it also doesn't require curly braces to parse correctly either. –  Exit Jan 6 '12 at 6:04
    
Yea, you're right too. Didn't look that close. And the curly brackets make the most sense for syntax highlighters (not here on WPSE, but in your IDE). Else it melts with the background. –  kaiser Jan 6 '12 at 9: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.