WordPress.org

Forums

Sticky Posts & Sortby Custom fields (3 posts)

  1. lifeless85
    Member
    Posted 6 years ago #

    I found out that i can sort my posts using
    query_posts('category_name=special-offers&orderby=meta_value&meta_key=from&order=ASC');
    before the loop
    but i'm in need to put sticky posts on top (for some reason if i sort them the sticky one's are sorted too)
    so i thought that adding:
    query_posts('caller_get_posts=0&category_name=special-offers&orderby=meta_value&meta_key=from&order=ASC');
    would do the trick, but it's not true ...

    Now i'm thinking about customizing the query a little harder so i can put two sort parameters, or something a-like
    Or doing two loop one done only of stikies and one without stikies and sorted ...
    But after hours of reading i'm here to ask if someone can help me telling his idea ...
    And also because i think this is a bad beaviour and i think that fallback sort criteria should be added, so we can use something like
    query_posts('orderby[]=meta_value&orderby[]=meta_value&orderby[]=title&meta_key[]=custom1&meta_key[]=custom2')
    so if two or more posts have custom field custom1 equal, the custom2 is compared and so on

    Sry for my bad english, greetings from italy

  2. westondeboer
    Member
    Posted 6 years ago #

    To do that your going to have to do a custom query. Your going to have to reference http://codex.wordpress.org/Displaying_Posts_Using_a_Custom_Select_Query

  3. lifeless85
    Member
    Posted 5 years ago #

    I've solved my issues by doing two custom query, and getting some info from wp with:
    $sticky=get_option('sticky_posts');
    the first query with theese parameters:

    $args=array(
    	'category_name'=>'special-offers',
    	'showposts'=>2,
    	'post__in' => $sticky,
    	'caller_get_posts' => 1,
    	'orderby'=>'meta_value',
    	'meta_key'=>'from',
    	'order'=>'ASC'
    );

    the second one with:

    $args=array(
    	'category_name'=>'special-offers',
    	'showposts'=>2,
    	'post__not_in' => $sticky,
    	'caller_get_posts' => 1,
    	'orderby'=>'meta_value',
    	'meta_key'=>'from',
    	'order'=>'ASC'
    );

    but that lead to the discover of a new bug !
    but there's a work around ... you need at least one stiky post, because of how post__in option is managed ... i'll post a link to the trak

Topic Closed

This topic has been closed to new replies.

About this Topic