• Skip to main content
  • Skip to forum navigation

StudioPress

  • Shop for Themes
  • My StudioPress

Forum navigation

  • Home
  • General Genesis Discussions
  • StudioPress Themes
  • Genesis Blocks
    • Genesis Blocks
    • Genesis Custom Blocks
  • Retired Themes
  • FAQs
  • Forum Rules
  • Internationalization and Translations
  • Forum Bugs and Suggestions
  • Forum Log In

Are You Using The WordPress Block Editor?

Genesis now offers plugins that help you build better sites faster with the WordPress block editor (Gutenberg). Try the feature-rich free versions of each plugin for yourself!

Genesis Blocks Genesis Custom Blocks

2 buttons to change the sort order of posts

Welcome!

These forums are for general discussion on WordPress and Genesis. Official support for StudioPress themes is offered exclusively at My StudioPress. Responses in this forum are not guaranteed. Please note that this forum will require a new username, separate from the one used for My.StudioPress.

Log In
Register Lost Password

Community Forums › Forums › Archived Forums › General Discussion › 2 buttons to change the sort order of posts

This topic is: resolved

Tagged: button, php, posts, sort order

  • This topic has 2 replies, 2 voices, and was last updated 11 years, 7 months ago by cyanoorange.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • March 27, 2015 at 5:24 am #145786
    cyanoorange
    Participant

    Hi,
    I have the following problem:
    I want to have two buttons [Ascending] [Descending] to allow the visitor of my page to change the sort order of the blog posts.
    I found the follwing script, which gives me a hint
    `<?php
    add_action( 'pre_get_posts', 'prefix_reverse_post_order' );
    /**
    * Reverse Post Order for Post Archives
    * on the Genesis Framework
    *
    * @author FAT Media
    * @link http://youneedfat.com/reverse-post-order-genesis-framework/
    * @param object $query data
    *
    */
    function prefix_reverse_post_order( $query ) {
    if ( is_admin() )
    return;
    // Only change the query for post archives.
    if ( $query->is_main_query() && is_archive() && ! is_post_type_archive() ) {
    $query->set( 'orderby', 'date' );
    $query->set( 'order', 'ASC' );
    }
    }

    BUT:
    I dont want an automatic solution. I want the posts sorted by standard, but if the user wants to change the order he could, by clicking on a button.
    And I dont knwo how I coud create a button which calls the php-script.
    Could anybody help me with this? Would be great.

    March 27, 2015 at 5:50 pm #145895
    Christoph
    Member

    Hi,

    did you see these two posts?

    http://stackoverflow.com/questions/28635595/wordpress-change-order-by-on-click
    http://stackoverflow.com/questions/5514901/how-to-change-wordpress-query-posts-by-clicking-a-link

    If that doesn´t work for you, you'd probably have to use jQuery to execute a function when the button is clicked.


    https://www.christophherr.com | Genesis Customizations | Buy me a coffee

    March 28, 2015 at 7:00 am #145934
    cyanoorange
    Participant

    Dear Christoph,
    I had googled a lot, but didn't find those two. Thanks a lot!!! The second link provides the information I needed.
    Thanks again and have a nice weekend.

  • Author
    Posts
Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘General Discussion’ is closed to new topics and replies.

CTA

Ready to get started? Create a site or shop for themes.

Create a site with WP EngineShop for Themes

Footer

StudioPress

© 2026 WPEngine, Inc.

Products
  • Create a Site with WP Engine
  • Shop for Themes
  • Theme Features
  • Get Started
  • Showcase
Company
  • Brand Assets
  • Terms of Service
  • Accptable Usse Policy
  • Privacy Policy
  • Refund Policy
  • Contact Us
Community
  • Find Developers
  • Forums
  • Facebook Group
  • #GenesisWP
  • Showcase
Resources
  • StudioPress Blog
  • Help & Documentation
  • FAQs
  • Code Snippets
  • Affiliates
Connect
  • StudioPress Live
  • StudioPress FM
  • Facebook
  • Twitter
  • Dribbble