• Hi,

    I use the awesome ACF plugin to associate posts with books. Now I want to create an archive page with a list of all posts ordered by the book titles.
    Something like:

    * Book 1
    ** Post 1
    ** Post 7
    * Book 2
    ** Post 4
    ** Post 5
    ** Post 2
    *Book 3
    ** …

    So far I came up with the following query

    $sql =
    "SELECT * FROM  $wpdb->posts po
    INNER JOIN $wpdb->postmeta pm ON ( po.id = pm.post_id )
    WHERE  pm.meta_key = 'book'
    AND po.post_status = 'publish'
    GROUP  BY po.id
    ORDER  BY pm.meta_value;

    The problem is this will give me the select field meta_value but not the name which is associated with the meta_value which in my case is the book name.

    How to extend the query to get this book name.

    Thanks

    martin

    http://wordpress.org/extend/plugins/advanced-custom-fields/

  • The topic ‘Post Archive List ordered by ACF select field name’ is closed to new replies.