WordPress.org

Ready to get started?Download WordPress

Forums

Creating a list of posts ordered by the values present in a custom field (12 posts)

  1. rpOliveira
    Member
    Posted 4 years ago #

    Hello, good community!

    I have spent some time reading and searching but I still didn't find a way to solve this problem.

    For each post I have custom-fields with numeric values. I would like a way to create a page with a list of posts ordered (in ascending or descending order) by the value of that custom-field.

    I found this plugin http://www.christianschenk.org/projects/wordpress-list-posts-custom-field-plugin/ that makes the list but doesn't have (yet) the ability to order the posts by the value in the custom-field (just by date, title,..)

    There must be a way to do this because I find it very useful to present a list of the posts of a blog ordered by rating, for instance.

    In my blog (it's a movie quiz - http://www.iknowthatmovie.com) I have three numeric values for each post:

    1) classification of the quiz's difficulty as voted by users
    2) number of users who have seen that film
    3) time to solve the quiz (in minutes)

    I would like to create pages with a list of posts oredered by these numeric values.

    Can anyone help me?

  2. gerbilk
    Member
    Posted 4 years ago #

    how about doing it client side with jquery? then you could change between the 3 ranking options.

  3. rpOliveira
    Member
    Posted 4 years ago #

    I don't have programming skills to do that and I don't understand what you mean.

    I was hoping someone knew some plugin or piece of code that could do this. I think it's useful and must be a common problem (to make a list of the posts ordered by ratings, for instance).

  4. gerbilk
    Member
    Posted 4 years ago #

    something like this
    query_posts('meta_key=$yourkey&orderby=meta_value_number&order=DESC');

    look here http://codex.wordpress.org/Template_Tags/query_posts

    and here http://wordpress.org/support/topic/277454?replies=6

  5. rpOliveira
    Member
    Posted 4 years ago #

    Hi! Thanks for your answer. I didn't know query_posts and tested it and it will be useful, for sure.

    However, that's not what I intended. I wanted a page with a list of the posts ordered by a numeric value (a text list with the titles of the posts). I want to create a new page that contains the post list, like this one: list made with the plugin.

    That plugin seems great but can't order the posts by a numeric value in a custom-field.

    I'm finding odd that nobody hasn't made this before :) It must be there somewhere.

  6. gerbilk
    Member
    Posted 4 years ago #

    the orderby=meta_value_number should order the posts by their numeric custom field value, or did you mean something different?

  7. rpOliveira
    Member
    Posted 4 years ago #

    I meant a page that has a text list of all my posts.

    Example:

    Ordered posts by ratings;

    1. Post Title 37 - 5.0
    2. Post Title 32 - 4.8
    3. Post Title whatever - 4.6
    4. Post Title hello - 4.5
    5. Post Title title - 4.1
    ...

    I don't want to alter the loop to display my posts by any kind of order. I want a page that is a list of links to my posts (ordered by some value). Each link has the text of the post title and points to it.

  8. gerbilk
    Member
    Posted 4 years ago #

    the idea is to use the loop (which you can have on any page using a custom page template and query_posts), use the query_posts I posted earlier with the key for your ratings, ordered by the value of the key, then inside the loop use something like

    <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> - <?php $key="mykey"; echo get_post_meta($post->ID, $key, true); ?></h2>

  9. rpOliveira
    Member
    Posted 4 years ago #

    So I can have another page with the loop and order the posts with query_post. But how can I create that page properly?

    Here is what I did: I went to my theme folder. I copied the index.php and created another file called order.php. The only difference in order.php is that I use query-posts to sort them in a different way. Now I have the order.php file in my theme folder. How to access it? How can I make a link in other pages to that file in order to present the sorted posts?

    I'm not seeing the whole picture here.

    Thanks.

  10. gerbilk
    Member
    Posted 4 years ago #

  11. rpOliveira
    Member
    Posted 4 years ago #

    Well, finally I got some time to take a look at this.

    Thanks a lot for your tips. I was able to do exactly what I wanted with your help - two lists of posts ordered by a numerical value.

    Here is the one ordered by the classification of the posts:

    http://www.iknowthatmovie.com/quizzes-list-by-difficulty/

    Here is the one ordered by the number of views of each post:

    http://www.iknowthatmovie.com/quizzes-list-by-views/

    I also used thumbnails in the lists.

    Thanks for your help.

  12. gerbilk
    Member
    Posted 4 years ago #

    no worries! site looks good.

Topic Closed

This topic has been closed to new replies.

About this Topic