Displaying posts sorting by a custom criterion

I wish to display my posts, not according to the date, but to a completely custom criterion. Ideally, I would manually set a numerical value to each post and the WP loop would display posts according to this value.

So if post X has value 1, post Y has value 2 and Z value 3, it would display first X, then Y, than Z, even though the date criterion would entail a different order. Hope it makes sense.

Read More

How to achieve this?

Related posts

1 comment

  1. Save the order in a Custom Field, then modify the main query to order on that custom field via pre_get_posts. Example for posts page:

    function wpa_custom_order( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'meta_key', 'your_order_key' );
            $query->set( 'orderby', 'meta_value' );
        }
    }
    add_action( 'pre_get_posts', 'wpa_custom_order' );
    

Comments are closed.