WordPress.org

Ready to get started?Download WordPress

Forums

HOW TO TURN FUNCTION OFF AND ON (1 post)

  1. agnesvarda
    Member
    Posted 3 years ago #

    I would like to turn a php function on and off, I've placed this code on my index.php

    <?php
    function default_sort_ascend($t) {
         $q = $t->query_vars;
         if ( empty($q['order']) || ((strtoupper($q['order']) != 'DESC') && (strtoupper($q['order']) != 'ASC')) )
              $q['order'] = 'ASC';
         $t->query_vars = $q;
    }
     add_action('pre_get_posts', 'default_sort_ascend');
    ?>

    How to create a button to switch back and forth from 'DESC' to 'ASC'?

    The code above is great because it affects not only the home page but also the archives, etc...

    Thank you

Topic Closed

This topic has been closed to new replies.

About this Topic