• Hi, I’m running a wordpress websise for a movie catalog to keep track of upcoming movies and the ones that I’m going to watch/already watched.
    There are several custom fields, that I want movies to be sorted by, namely date of original release, release in estonia and seen (yes/no). I also want them to be sorted by title on ‘all movies’ page, but taking into account definite/indefinite articles (a, an, the). I want the code to be as much ‘wordpress native’ as possible and compact to avoid clutter and inconsistence on different page templates.
    So, I would like to have these pages:
    – index page with 2 queries – the first one retrieves, say, 12 upcoming movies (wordwide release date and estonian release date > current date, sorted by release date) and the second one retrieves 24 unwatched movies (seen = no, release dates > current date, random sorting), no pagination required
    – 2 separate pages, that retrieve 2 lists described above with pagination and sorting by title (with articles kept in mind)
    – page that lists all movies that are currently shown in cinemas in estonia (release in estonia = current date + 2 weeks)
    – page with all the movies listed with pagination, sorted by title with articles
    – page with all movies that I have seen, paginated, sorted by title with articles

    I have 2 options that I might use, but neither fully satisfies my needs.
    1) query_posts();
    query_posts('posts_per_page=24&orderby=date&order=DESC'.'&paged='.$paged);
    this allows me to paginate results and reduces the overall code amount, but I’m not able to use 2 or more custom fields for filtering and proper ordering by movie title
    2) using normal MySQL query and $wpdb->get_results($querystr, OBJECT);
    this gives me freedom for multiple custom fields filtering ang allows proper title ordering but I’m not able to paginate results.

    Can anyone please help me out with that? Sorry for the long post and possibly unclear explanation, please ask for clarification.

Viewing 3 replies - 1 through 3 (of 3 total)
  • For choice 2), you can paginate any array by using your own pagination code. See the example here in the pastebin.

    Thread Starter defeed

    (@defeed)

    Thank you, that seems to be the only solution for me by now. Would be great to use pagination as a plugin or be able to filter by more than one custom field key/value in query_posts though.

    There are some pagination plugins, but I have not tried them.

    You can filter by more than one key/value pair by using filters to modify the query, so you can continue to use query_posts(). See the example in this thread.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘custom query w/ multiple custom fields filtering and pagination’ is closed to new replies.