• Hi,

    I am using the query string example form the codex, and it works great.
    https://codex.www.ads-software.com/Displaying_Posts_Using_a_Custom_Select_Query

    <?php
    
    	 $querystr = "
    	    SELECT wposts.*
    	    FROM $wpdb->posts wposts, $wpdb->postmeta wpostmeta
    	    WHERE wposts.ID = wpostmeta.post_id
    	    AND wpostmeta.meta_key = 'kids_book'
    	    AND wpostmeta.meta_value = 'yes'
    	    AND wposts.post_status = 'publish'
    	    AND wposts.post_type = 'post'
    	    AND wposts.post_date < NOW()
    	    ORDER BY wposts.post_date ASC
    	 ";
    
    	 $pageposts = $wpdb->get_results($querystr, OBJECT);
    
    	?>

    I have another meta key in these posts called ‘book_sort’ I would like the sort order of my posts to be the value of ‘book_sort’

    So how do i work something like this:

    'meta_key' => 'book_sort',
    'orderby' => 'meta_value'

    …into the above query string.

    Thanks!

    Nadine

  • The topic ‘Query String and custom field sort’ is closed to new replies.