Take your website
To the next level
Discover our newly launched customization services and elevate your web projects to new heights.
Delegate tasks, save time, and unlock the power of professional WordPress outsourcing.

Okay
  Public Ticket #1807696
Possible to sort post by name
Closed

Comments

  • Cecdah started the conversation

    Hi. Love your theme, but i am missing one feature from the News and blog element.

    I am wondering if there is any possibility to sort the post by name or Ascendig, Descending. Now it only sort by latest post.

    Is there any way to do that, maybe adding a function or something.


    Regards

  •  7,095
    Oliver replied

    Hi,

    Small example:

    function order_posts_by_title( $query ) {    
    if (is_home()) {
    $query-set( 'orderby', 'title' );        
    $query->set('order', 'ASC');    }
    }
    add_action( 'pre_get_posts', 'order_posts_by_title' );

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver

  • Cecdah replied

    Hi

    We were able to create an option for sorting by altering the shortcodes.php file in theme-elemets.

    How do we make sure that our codes dont get overwriten next time we update the theme-elements plugin?

    Note that we are using a child theme, but we can't figure out how to get shortcodes.php to work from the child theme


  •  7,095
    Oliver replied

    Hi,

    Sorry, there are no simple way to overwrite it in the child theme. Here the example of query:

    add_action( 'pre_get_posts', 'custom_post_type_order' );
    function custom_post_type_order($query){
        if( is_admin() ) {
            return $query;
        }
        if ($query->query_vars['post_type'] == 'thegem_pf_item'' ) {
            $query->set('order', 'DESC');
        }
    }
    

    But sorry,  I'm not sure that it will work correctly everywhere. 

    Please note if you comment on your ticket before we reply, your ticket will be pushed down of the tickets list. 

    Regards, Oliver