• Hi, when I first created my reading blog using WP, custom fields were not very common, so I created fields for the ratings in a table in my database. I can access my posts in single.php and make a custom query to show the rating from the table using this code:

    $results = get_review($post->ID);
    if (mysql_num_rows($results) > 0)
    {
    $fields = mysql_fetch_row($results);
    $rating = $fields[1];
      }

    In single.php I already have the ID of the post, so it’s easy to retrieve the fields I need and it’s working fine. But now I would like to create an Archive page where I could sort my posts by ratings. For example: all posts with a rating of ‘5’ or ‘3’. I can’t use the archive.php from WP and if I create a custom query, then the WP pagination will be broken…

    I’ve searched on Google and the WP Forums with no success, and I’m stuck so I hope someone will be able to help me. I’m not a coder so maybe it seems easy to do but I couldn’t find a way to do it so far… Thank you for you help! 🙂

Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    To maintain pagination, you’d need to alter the SQL query WP creates to fulfill the archive request. Your table needs to joined and the orderby clause set to use that table’s data. This can be done through the “posts_clauses” filter. I’m sorry, but I’m unable to offer specific code for this. If you tell us what your table name is and what column to order by, someone else may be able to work something up for you. Also, would this apply to any archive query, including category or tag queries (i.e. anything where is_archive() is true)? If not, then specifically what requests?

    If no further assistance appears forthcoming here, you might consider hiring someone from jobs.wordpress.net or jetpack.pro. Since this wouldn’t involve a lot of time, it shouldn’t be too expensive.

Viewing 1 replies (of 1 total)

The topic ‘Custom Archive from non-WP Database’ is closed to new replies.