Support » Fixing WordPress » Sticky posts doesn’t work on query_posts?

  • Resolved akis


    I have the following code:

    $sixt_id = get_catId("Blog");
    $sixt_id .= ",".get_catId("Featured");
    $sixt_id .= ",".get_catId("Premium");
    if (have_posts()) : while (have_posts()) : the_post();
    echo get_the_title();

    On featured category I have a sticky post, but doesn’t show up in front, why?

Viewing 15 replies - 1 through 15 (of 21 total)
  • Thanks. I have checked those but didn’t help, I don’t want to display only sticky posts, I just want the normal behavior.

    Stickies should already be included in the query, unless they’re not matched against the parameters you’ve set, ie. within the categories above (blog, featured, premium).

    They are included but like normal posts not stickies.

    Try setting the caller_get_posts parameter (try both values, 1 and 0, should only take a minute).

    Tried that already, nothing changed.

    I have no idea why they’re not retaining the order, if you remove the query posts line do stickies then behave correctly? (simply to test).

    Yes, but unfortunately this is not a solution.

    Some related question:
    Do you have any idea if its possible to prioritize posts from Featured category?

    Was never intended to be a solution, simply a test to see if the problem is still apparent.

    Query posts should work with stickies if caller_get_posts is set accordingly, but i do remember a thread from a while back that i answered where another user had the same problem, i’ll see if i can dig it up.. (will edit post if i can find it).

    EDIT: Here’s the thread i mentioned which contains a work-around for the problem.

    Not sure what you mean on your related question, can you elaborate please?

    My code displays last six posts from those 3 categories.
    If possible, I want to show posts from Featured category first. Featured may contain posts from Blog and other categories.

    It seems that using this query, sticky posts are displayed fine but the showposts count no longer works, it displays 6 normal posts + x sticky posts. Do you have any ideea why?

    query_posts("showposts=6&".array('category__in' => array($sixt_id)));

    You can’t combine a string and an array, either use an array or a string for the parameters.

    Try this..

    query_posts( array( 'posts_per_page' => 6, 'category__in' => array( $sixt_id ) ) );

    NOTE: Changed to posts_per_page as showposts is deprecated, however showposts does still work(currently), simply showing you the new way… 🙂

    For some reason now it displays posts only from the first category (Blog).

    You variable is not an array, it’s a string.. (i missed that before).

    Change this.

    $sixt_id = get_catId("Blog");
    $sixt_id .= ",".get_catId("Featured");
    $sixt_id .= ",".get_catId("Premium");


    $sixt_id = array( get_catId("Blog"), get_catId("Featured"), get_catId("Premium") );

    ..and as the variable is now an array, change this..

    query_posts( array( 'posts_per_page' => 6, 'category__in' => array( $sixt_id ) ) );


    query_posts( array( 'posts_per_page' => 6, 'category__in' => $sixt_id ) );

    Or, just do this..

    query_posts( array( 'posts_per_page' => 6, 'category__in' => array( get_catId("Blog"), get_catId("Featured"), get_catId("Premium") ) ) );

    Sorry for the delay, still doesn’t work.
    Using an array for posts_per_page seems to disable the sticky behaviour.

    What I really want:
    – I’m showing six posts from Blog category on homepage (ordered by date)
    – Here, I want to promote (give priority) to some old posts (from the Blog category)

    Any ideea how to achieve this?

Viewing 15 replies - 1 through 15 (of 21 total)
  • The topic ‘Sticky posts doesn’t work on query_posts?’ is closed to new replies.