WordPress.org

Ready to get started?Download WordPress

Forums

Ordering posts (13 posts)

  1. Rub3X
    Member
    Posted 7 years ago #

    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.

  2. pizdin_dim
    Member
    Posted 7 years ago #

    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".

  3. Rub3X
    Member
    Posted 7 years ago #

    Sorry what's $query_string ?

  4. Rub3X
    Member
    Posted 7 years ago #

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

  5. pizdin_dim
    Member
    Posted 7 years ago #

    It works for me, read the Codex.

  6. Rub3X
    Member
    Posted 7 years ago #

    $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.

  7. Rub3X
    Member
    Posted 7 years ago #

    The SQL query it's doing is

    ORDER BY post_date desc

    Obviously not the function I need.

  8. Samuel Wood (Otto)
    Tech Ninja
    Posted 7 years ago #

    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.

  9. Rub3X
    Member
    Posted 7 years ago #

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

  10. davidchait
    Member
    Posted 7 years ago #

    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.

  11. niklasbackman
    Member
    Posted 6 years ago #

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

  12. parweb
    Member
    Posted 6 years ago #

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

    sorry for my english

  13. komments
    Member
    Posted 6 years ago #

    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 (http://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.

Topic Closed

This topic has been closed to new replies.

About this Topic