• Resolved techsmurfy

    (@techsmurfy)


    Hello,

    First of all let me say thank you for this awesome plugin. I tested over 10 similar plugins before selecting this one. I’m using PiS to display popular posts from the last x days by selecting a meta key where my views are stored.

    But part of the reason I chose to use it was because I had high hopes that it could do the same in single posts from current category (i.e. displaying popular posts of that category), but unfortunately as I realized in my debugging, all date, meta key etc. parameters I have set are empty. And then this came to my attention

    When activated, this function will get posts from the first category of the post, ignoring other parameters like tags, date, post formats, etc.

    but why, really? Isn’t there a way NOT to ignore them? Either by modifying the way the widget works or even a shortcode? This would be a very helpful addition.

Viewing 12 replies - 1 through 12 (of 12 total)
  • Thread Starter techsmurfy

    (@techsmurfy)

    (To clarify; by reading the description above, I misunderstood that the function, except for the main category, would ignore all the current post’s characteristics, NOT the widget’s filled-in parameters for the query. Hence my confusion when it happened.)

    Plugin Author Aldo Latino

    (@aldolat)

    Hello,
    I’ve just added a new option to not ignore other parameters when on single posts. This should be enough for you. You can make a test by downloading the plugin from GitHub and uploading it to your server overwriting the old version.

    At the end of the section “Change the query when on single posts” you will find a new option with a yellowish background “Do not ignore other parameters”. Activate it and test the results. When this option is active, the plugin will not ignore parameters like tags, authors, date, and so on.

    Let me know if it works for your needs.

    Thread Starter techsmurfy

    (@techsmurfy)

    Wow. That’s a hell of a quick response AND support.
    Seems to work just fine after a quick few tests. Will report if I notice anything out of the ordinary.

    I so much appreciate it. In fact, I’m a bit surprised this option wasn’t there in the first place. I will seriously consider donating as soon as our business gets off the ground, or even contribute a translation when time permits.
    Thank you!

    ***********************

    I’m getting a little bit off-topic, but I also noticed that in the case of multiple categories – note: I use a plugin to arrange the display order of my categories – PiS doesn’t pick the one with the lowest ID (as WordPress does for its permalinks), but the first in my arranged order. I suppose it is wise not to use a system with the lowest ID, but then again now in single posts there are discrepancies between the category WordPress picks as a main category for its permalink, and the category picked by PiS to display posts from.

    For example, got post_A, with cat_1 and cat_2, in that display order. But cat_2 has the lowest ID cause it was created first. So it’s like:
    * permalink: https://…url…/cat_2/post_A_title
    * PiS widget: showing posts from cat_1

    And unfortunately Yoast’s option to choose a primary category for each post does not work with PiS’s current category option (and I don’t currently use that option cause I’d rather have a more automated system). So I don’t know, thoughts?

    I suppose a workaround for the time being would be to add an option to pick the category based on lowest ID instead, just like you did for my previous request? Another alternative would be to add a Yoast primary category for all 30k posts and then use your custom_field instead of the current category option, as you described here.

    • This reply was modified 7 years, 11 months ago by techsmurfy.
    Plugin Author Aldo Latino

    (@aldolat)

    You’re welcome, @techsmurfy ??

    I’m getting a little bit off-topic… [cut]

    PiS uses the standard WordPress functions to retrieve the terms of a given post, such as get_the_category() and get_the_term_list(). These functions return the terms in an array alphabetically sorted. In this situation the term with the lowest initial letter has always the lowest key ID in the returned array. On the contrary, WordPress uses the term with the lowest ID in the permalink. I think you’re right pointing this out, so I made some changes.

    @techsmurfy, you know what I am talking about, so for the other readers, who are a bit confused about this, I explain here the difference in these two IDs.

    Let’s say that in a post we use 2 categories:
    Category B where the ID assigned by WordPress is 100
    Category C where the ID assigned by WordPress is 200

    When we save the post, WordPress will use “Category B” as the main category of the post, because it has the lowest ID. This category will also be used in the permalink of the post (if we use the category in the permalink), for example: https://www.example.com/category-b/title-of-the-post

    Let’s say that after some time, we change the categories of the post, and that we use two other categories:
    Category A where the ID assigned by WordPress is 300
    Category Z where the ID assigned by WordPress is 50

    Now the post has four categories:
    Category A where the ID assigned by WordPress is 300
    Category B where the ID assigned by WordPress is 100
    Category C where the ID assigned by WordPress is 200
    Category Z where the ID assigned by WordPress is 50

    The main category now will be “Category Z”, because it has the lowest ID (50). But when we retrieve the list of the categories of the post using a PHP function like wp_get_post_categories(), WordPress builds an array, alphabetically sorted, like this:

    
    Array
    (
        [0] => 300 (Category A)
        [1] => 100 (Category B)
        [2] => 200 (Category C)
        [3] => 50  (Category Z)
    )
    

    where 300 is the “Category A” that has the lowest key ID in the array [0]. (If in this example we would have added only “Category A”, the main category would have been “Category C”, as it was before the change.)

    Until version 3.8.3 PiS has retrieved the categories of the current post based on this array, so it has got posts from “Category A”, which has the lowest key ID in the array. Starting from 3.8.4, PiS will get posts from the category with the lowest ID (not key ID of the array), like WordPress does. In the last example, PiS will get posts from “Category Z”, that has 50 as its ID.

    In order to make this, I just changed the way PiS gets the categories of the current post. Now PiS sorts the categories of the post from the lowest ID to the highest. In this way we are sure to get posts from the category used by WordPress in the permalink.

    @techsmurfy if you could download the new development version from GitHub and make a test, I really appreciate it.

    Let me know, please.

    Thread Starter techsmurfy

    (@techsmurfy)

    It works, as far as I know. Indeed, now wordpress main category concurs with PiS displayed category!

    But, hold on a sec ??
    I do believe that your former way of how PiS gets the categories is wiser (albeit, more difficult for users to understand). Why? Because it’s easier for a user to change it, using a plugin.

    Indeed, categories are (were) displayed alphabetically, which means, in your example, that PiS will use Category A as its main category (despite what WordPress does). BUT, with any plugin that changes the display order, I can easily set Category B to display first with a simple drag & drop. And PiS sees that and picks Category B now (while WordPress still picks the same cat).
    note: of course, that applies for all posts, and all locations where a categories list is displayed, unfortunately; you can’t do that on a per post basis
    This means that with your former way, the user has, at least, the option, if he chooses to, to change the display order of categories, unlike the latter way, where I am not familiar with any way to change a category’s ID without screwing everything up (of course you can manually move all posts to another category, but that’s another story).

    All in all,
    lowest key ID in the array
    Pros: more flexibility
    Cons: may confuse users, may differentiate from what wordpress does

    lowest ID
    Pros: concurs with wordpress, easier to understand
    Cons: users can’t mess with category prioritization at all (not in any automatic way at least)

    Which is why, in my previous post, I suggested to add an (advanced) option for a user to choose the way that PiS selects the post’s main category. If I had to choose one of the two for a default, yeah, probably the lowest ID would be my choice so not to confuse users, but an extra array sorting option would be a welcome addition.

    • This reply was modified 7 years, 11 months ago by techsmurfy.
    Plugin Author Aldo Latino

    (@aldolat)

    I totally agree with you. I just added a new option to sort categories. The new snapshot in on GitHub.

    Let me know.

    Plugin Author Aldo Latino

    (@aldolat)

    Hello @techsmurfy,
    I just released the version 3.8.4. Since probably you’re using the development version 3.8.4-dev from GitHub, if you do not receive the update notification, update manually downloading the stable version from the WordPress repo.

    Bye.

    Thread Starter techsmurfy

    (@techsmurfy)

    Hello @aldolat

    I’m terribly sorry for being late to reply/debug, I was so busy this week I could not lift a finger :/

    I’m testing your update right now. It seems to me that end results are inverted? As soon as I tick the new “Sort categories” option, I get posts with the lowest ID, if I leave it default (unticked), I get posts with the lowest key ID in the array. If that was indeed the intention, and not the other way around, then the description probably confused me.

    But despite this little confusion, bottom line is that it works! Did I ever tell you how awesome you are?

    This is just great ??

    Plugin Author Aldo Latino

    (@aldolat)

    I’m terribly sorry for being late to reply/debug, I was so busy this week I could not lift a finger :/

    I’m in the same situation. ??

    I’m testing your update right now. It seems to me that end results are inverted? As soon as I tick the new “Sort categories” option, I get posts with the lowest ID, if I leave it default (unticked), I get posts with the lowest key ID in the array. If that was indeed the intention, and not the other way around, then the description probably confused me.

    Yes, this is what I understood from our conversation. Perhaps the description is not so well written? I’m not a native English speaker…

    Did I ever tell you how awesome you are?

    I’m very happy reading this! You too are awesome, you and all the users of this piece of code that is named Posts in Sidebar.

    Hugs from Italy.

    • This reply was modified 7 years, 11 months ago by Aldo Latino.
    Thread Starter techsmurfy

    (@techsmurfy)

    Yes, this is what I understood from our conversation. Perhaps the description is not so well written? I’m not a native English speaker…

    No, your english is excellent. Let me rephrase it: we were aiming to let the user choose which way they want their categories to be sorted; by lowest ID or by lowest key ID in the array. In your description, you say “if the post has multiple categories, the plugin will use the category with the lowest ID”. BUT If the user does NOT tick the “Sort Categories” option on the right, then the plugin will NOT use the category with the lowest ID. It will just use the lowest key ID in the array, as it was being done until recently. In order for the description to be true, the user HAS to tick the Sort Categories.

    I’m just trying to make sure this is what you wanted, cause I thought that it would be working the other way round; that the plugin would sort categories and pick the one with the lowest ID, UNLESS the user would tick the ‘Sort Categories’ option, where it would pick the first in the array, as previously.

    In short, if it stays like this, I’m only suggesting that the part of the description where you say “if the post has multiple categories, the plugin will use the category with the lowest ID” would be moved under the ‘Sort Categories’ option to make more sense.

    Posts in Sidebar - sorting multiple categories

    Kudos, from Greece ??

    Plugin Author Aldo Latino

    (@aldolat)

    @techsmurfy you’re so great! I just made a new release only to update a description. ??

    Thanks!

    Thread Starter techsmurfy

    (@techsmurfy)

    Awesome! ??

    I will keep you updated if anything else comes up.
    Thanks again!

Viewing 12 replies - 1 through 12 (of 12 total)
  • The topic ‘How not to ignore parameters on single posts’ is closed to new replies.