• I have a cost column in wp_posts, and I need to order the posts by the highest number in the cost column. Where is the SQL query that lists posts – or what are alternative ways.

Viewing 12 replies - 1 through 12 (of 12 total)
  • According to the Codex, you should be able to do this:

    $posts = query_posts($query_string . '&orderby=xxxx&order=desc');

    where “xxxx” is your custom posts column name. Put it just before “the loop”.

    Thread Starter Rub3X

    (@rub3x)

    Sorry what’s $query_string ?

    Thread Starter Rub3X

    (@rub3x)

    Hmm I added $posts = query_posts($query_string . ‘&orderby=cost&order=desc’); before the loop and there was no change ;(

    It works for me, read the Codex.

    Thread Starter Rub3X

    (@rub3x)

    $posts = query_posts($query_string . '&orderby=cost&order=desc');
    <?php if (have_posts()) : ?>
    	<?php
    while (have_posts()) : the_post(); ?>
    			<!-- post start -->
    			<div class="clearfix post">
    				<h1><?php the_title(); ?></h1>
    					<?php the_content('Site Details'); ?>
    			</div>
    			<!-- post end -->
    		<?php endwhile; ?>

    That’s exactly what I have.

    Thread Starter Rub3X

    (@rub3x)

    The SQL query it’s doing is

    ORDER BY post_date desc

    Obviously not the function I need.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    The orderby parameter only works with:
    ‘author’, ‘date’, ‘category’, ‘title’, ‘modified’, ‘menu_order’

    In 2.1.3, this is in the wp-includes/query.php file on line 901. If you add your column to this, it should allow it. Note that you’ll have trouble upgrading later if you’re using custom columns and core hacks and such stuff as this.

    Thread Starter Rub3X

    (@rub3x)

    Yea I got it after my last post. Edited the cost clause in manually, and surprisingly WP is still functional ??

    at some point I’ll have to release my custom ordering plugin. it works off a custom field, but sorta requires you always use it on all posts. Good for vertically-oriented uses of WP.

    Hi,
    Can you view/list the Posts by Custom field? The way you can reorder Pages by their Page Order?

    @rub3x have you resolv your problem because i would like to make same ?

    sorry for my english

    A little background – I am not a programmer but I can follow directions.

    I am using WordPress 2.0.2 and recently my posts started appearing out of order. When my page loads (https://www.pcstupidity.com) the oldest posts appear first. This also occurs when I go to the Manage section and look at my last 15 posts (it shows the first 15).

    I did not find a query.php file so I am unsure how to fix the this. I haven’t found a section in the Admin pages that allows me to set sort order for posts nor do I know what file in the WordPress group that needs to be modified.

    If anyone can point me at the correct file I should be able to find out where the Order By date descending is located.

    I would prefer not to have to upgrade the software if at all possible.

    TIA.

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘Ordering posts’ is closed to new replies.