WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Prioritizing posts by category in a date-sorted loop (40 posts)

  1. ggg377
    Member
    Posted 1 year ago #

    Hey keesiemeijer, thanks for the code. I implemented it, but it doesn't seem to work properly. Some sorting does take place, but that is very occasional and I couldn't find a pattern why some posts got moved. Moving of posts from the default arrangement was very rare.

    functions.php: http://pastebin.com/P1LPxmdH
    index.php (switched the code I had for pagination for this):

    <?php
    $dates_per_page = 4;
    get_index_pagination_nav( 'nav-below', $dates_per_page);
    ?>

    I also left the bugged implementation up at the example site.

    It would definitely be cooler to use a more optimized code, so I'm all in as far as co-operation :)

  2. keesiemeijer
    moderator
    Posted 1 year ago #

    That's strange. Are they in their normal chronolicical order now? Also check if the posts that are wrong are assigned to multiple categories or not? Are the posts per day correct or are there posts missing?

    If it's only the post order that is wrong (no posts missing) we can still use the query but have to sort it manually so that it sorts on category top first.

  3. ggg377
    Member
    Posted 1 year ago #

    I added a bunch of different posts to Today with different categories to test the code. The posts go from 1-26 in chronological order (from 1 oldest to 26 newest).

    It seems that in general if a post is only in the category "test", it always gets moved to the top. However there's a "test" post on February 2 that didn't get moved to the top. Usually if a post is in multiple categories it doesn't get moved to the top, but sometimes they still do (1 post under Today and 1 under February 3). Also what I noticed is that when I added test posts, the post that had multiple categories, but was on top for whatever reason, changed. At one point it was a post which had 3 categories in addition to "test" and then it changed to a post, which only had "Uncategorized" in addition to "test". Once again, I wasn't able to notice a correlation.

    No posts seem to be missing.

    You can check out the test posts until February 3. Everything is in chronological order from oldest to newest.

  4. keesiemeijer
    moderator
    Posted 1 year ago #

    I cannot reproduce the wrong sorting so I don't know what's going on. It could be our versions of sql is different. I've altered the code so it's still uses the one query to get the dates and ids (in the wrong category order) and it uses some extra queries to check if it's the top cat. But still better than before.

    Can you test this functions.php code: http://pastebin.com/z15V7zPk

  5. ggg377
    Member
    Posted 1 year ago #

    I tested the code. Prioritizing seems to work correctly now, but a weird string of numbers now appears in the header of the page. Also pagination seems to work differently, but I'm not sure.

    functions.php: http://pastebin.com/BTTeGfuw
    live page: http://goldenred.web44.net

    edit: new posts are loaded as soon as I'm halfway into "Today". This doesn't happen with my previous code (posts are loaded after scrolling through 4 dates).

  6. keesiemeijer
    moderator
    Posted 1 year ago #

    Ah the string was for testing, could you remove this:

    echo $post_id;
  7. ggg377
    Member
    Posted 1 year ago #

    Deleting that line fixed the string and pagination issues. It seems to be perfect now. Cheers!

    What happened to the original code you proposed anyway? Is there anything I could do to help you figure it out or is it not worth getting into?

  8. ggg377
    Member
    Posted 1 year ago #

    Edit: the category archives aren't scrolling in this code. For example when I open the "Uncategorized" archive by clicking on uncategorized in a post (in the sample site), then the newer posts show, the older don't and there is no navigation and therefore no scrolling. I might look into this myself later, but if it's a quick fix, I'll be happy to hear your suggestions. I'll need this functionality and the previous script does that for me.

  9. keesiemeijer
    moderator
    Posted 1 year ago #

    Ok, maybe the old way is more reliable. Just revert back to the first (or backed up) version of functions.php.

    This code was never intended to work on category pages? Are you sure it worked before?

  10. ggg377
    Member
    Posted 1 year ago #

    Hey keesiemeijer, sorry for the delay. I reverted back to the old version. The category navigation does work if there's more posts (however it does show duplicate labels and the number of dates on a page varies randomly). Kind of a shame the more optimized piece of code went to waste, but the code I have does do the job for now :)

Topic Closed

This topic has been closed to new replies.

About this Topic