Support » Plugin: Query Wrangler » Select one sticky post from each category

  • Hi
    What if I have 3 categories and I want to select only one sticky post from each category.

    I have get_sticky_posts as filter in callback. But I just need one post from each category…

    function get_sticky_posts($args){
    $sticky = get_option( ‘sticky_posts’ );

    return $sticky;
    }

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Jonathan Daggerhart

    (@daggerhart)

    Hi wooody,

    If these are legit core-WP “category” taxonomy terms, then you could make this happen easily w/ a single query used three times.

    1. Make a query and configure the display how you’d like.
    2. Then limit the “posts_per_page” to 1 and allow it to include stick posts. Do not include a category or taxonomy filter.
    3. Display that new query three times using the shortcode or widget and a dynamic argument that uses a “category_name” filter.

    For example, if your shortcode was [query slug=“test”] and you wanted it to show to categories with the slugs of “cat”, “dog”, and “saber-toothed-tigers”:

    [query slug="test" args="category_name=cat”]
    
    [query slug="test" args="category_name=dog”]
    
    [query slug="test" args="category_name=saber-toothed-tigers”]
    

    The above code will show the query three times, each limited by the category passed into the shortcode or widget.

    Hope this helps, let me know how it works out!
    Jonathan

    Thank you Jonathan

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Select one sticky post from each category’ is closed to new replies.