WordPress.org

Ready to get started?Download WordPress

Forums

previous/next_post_link() ordered by custom (1 post)

  1. abound
    Member
    Posted 5 years ago #

    I'm developing a business directory with WordPress. The "members" category is ordered by the "city" custom value. I have a nice query that makes this happen (based on a codex query):

    <?php
    
     $querystr = "
    SELECT * FROM $wpdb->posts
    LEFT JOIN $wpdb->postmeta ON($wpdb->posts.ID = $wpdb->postmeta.post_id)
    LEFT JOIN $wpdb->term_relationships ON($wpdb->posts.ID = $wpdb->term_relationships.object_id)
    LEFT JOIN $wpdb->term_taxonomy ON($wpdb->term_relationships.term_taxonomy_id = $wpdb->term_taxonomy.term_taxonomy_id)
    WHERE $wpdb->term_taxonomy.term_id = 3
    AND $wpdb->term_taxonomy.taxonomy = 'category'
    AND $wpdb->posts.post_status = 'publish'
    AND $wpdb->postmeta.meta_key = 'city'
    ORDER BY $wpdb->postmeta.meta_value ASC
    ";
    
     $posts = $wpdb->get_results($querystr, OBJECT);
     ?>

    All works very well until I get to the single.php template for this category. Here, the navigation previous_post_link() and next_post_link() functions are not jiving with the custom order in the category.php template.

    How can I create a custom query that changes the order of the prev/next post links based on the query above for my single.php template?

Topic Closed

This topic has been closed to new replies.

About this Topic