Support » Plugin: This Day In History » Table sorting 3.8.1

  • Resolved astrowhiz

    (@astrowhiz)


    Hi,
    I’ve just noticed with version 3.8.1 that my tdih tables are sorting by month 1st then by day then year

    Setting order_dmy to 0 or 1 doesn’t alter the sorting order. I’d like the default chronological sort order of year 1st then month, then day

    My code for the page is [tdih_tab period=a type=pc15 show_type=0 date_format=’j/n/Y’ order_dmy=0]

    Taking the custom php date format out doesn’t alter the table sorting.

    Anyone know where I’m going wrong?

    The page I need help with: [log in to see the link]

Viewing 5 replies - 1 through 5 (of 5 total)
  • Thread Starter astrowhiz

    (@astrowhiz)

    So I’ve changed this php in the tdih_shortcodes file –

    if ($period_days === false) {

    $order = $order_dmy === false ? ‘ ORDER BY LENGTH(p.post_title) DESC, p.post_title ASC’ : ‘ ORDER BY SUBSTR(p.post_title, -2) ASC, SUBSTR(p.post_title, -5, 2) ASC, LEFT(p.post_title, LENGTH(p.post_title) – 6) ASC’;
    }
    else {
    $order = ‘ ORDER BY SUBSTR(p.post_title, 1, 4) ASC, SUBSTR(p.post_title, 6, 2) ASC, SUBSTR(p.post_title, 9, 2) ASC, p.post_content ASC’;
    }

    I’ve taken out all order_dmy references in the table shortcodes and this now sorts tables in correct chronological order. I’m not sure why the IF is defaulting to the ELSE statement though.

    I do remember now that I had to change the code before but forgot with the new updates.

    Thread Starter astrowhiz

    (@astrowhiz)

    Just to follow up on this could I request Brokencrust have a look at the sorting code in TDIH_shortcodes starting at line 142.

    I think this is the default code that should sort chronologically –

    ORDER BY LENGTH(p.post_title) DESC, p.post_title ASC

    Unless I’m missing something this won’t sort as intended as the field is VarChar I think. The 2nd option in the ternary sorts D-M-Y and the code after the Else sorts M-D-Y.
    It would be useful, for me anyway, to have the default be chronological.

    Cheers

    Thread Starter astrowhiz

    (@astrowhiz)

    Ok so I think the code I posted previously does sort chronologically, it’s just that the previous code is skipping the IF and going to the ELSE

    The code here line 131 –
    $period_days = abs(intval($period_days)) < 100 ? abs(intval($period_days)) : false;

    Sets period_days value, which is later tested for falseness. I think the problem is period_days is taking a default value (maybe 0) and so doesn’t get set to false, even if period_days isn’t declared in the shortcode.
    I’ve been able to trigger chronological sorting by setting period_days=101 in the TDIH shortcode

    Plugin Author BC

    (@brokencrust)

    I guess that you’ve missed something.

    The sort order does sort chronologically. It picks out the BC dates first and them sorts those in order and then sorts the rest in order. However you choose to display dates they are always stored in YYYY-MM-DD order in the database with a leading minus for BC dates.

    This seems to work fine for me.

    Thread Starter astrowhiz

    (@astrowhiz)

    Hi,
    Thanks for your reply. Yes the order by length… code does sort chronologically, I was on the wrong lines with that.

    I still have a problem where $period_days never evaluates to false however, so the IF statement on line 140 always goes to the ELSE.

    I can trigger $period_days to false by amending line 131 to –

    $period_days = abs(intval($period_days)) < 100 && abs(intval($period_days)) > 0 ? abs(intval($period_days)) : false;

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Table sorting 3.8.1’ is closed to new replies.