WordPress.org

Ready to get started?Download WordPress

Forums

Advanced Recent Posts Widget
[resolved] Option to sort by post slug (3 posts)

  1. flashbytes
    Member
    Posted 1 year ago #

    Hello folks,

    does anybody know how to change the plugin files in order to have an additional option in the widget to also sort by the post slug?

    Thanks!

    Flashbytes

    http://wordpress.org/extend/plugins/advanced-recent-posts-widget/

  2. flashbytes
    Member
    Posted 1 year ago #

    Ok, I tried replacing
    <option value="title"<?php selected( $instance["sort_by"], "title" ); ?>>Title</option>
    with
    <option value="name"<?php selected( $instance["sort_by"], "name" ); ?>>Name (post slug)</option>

    See: http://codex.wordpress.org/Class_Reference/WP_Query#Order_.26_Orderby_Parameters

    This should have caused the orderby variable for the $my_args to be "name" instead of "title" in the WP_Query.

    But it didn't work. The recent post now are just ordered by date but reverse.

    PS: I looked up the values in the database and it clearly states:
    "s:7:"sort_by";s:4:"name";"

  3. flashbytes
    Member
    Posted 1 year ago #

    Yay, I got it.

    You also need to change the following line:
    $default_sort_orders = array('date', 'title', 'comment_count', 'rand');
    to
    $default_sort_orders = array('date', 'name', 'comment_count', 'rand');

    Or maybe not. ;) It works now. :)

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic