• Resolved jewelsmac6

    (@jewelsmac6)


    Hello! I have added the shortcode to my homepage and it looks great! However, the latest additions to my Petfinder account appear at the bottom of the list. Is there any way to sort the list so that the most recently added animals appear at the top of the list?

    My site is: https://heartsherd.com and we just added Clyde to our Petfinder list. You will see here that he appears at the bottom, and we would like to reverse the order of the list so that the most recently added animals appear first at the top.

    Thank you for a great plugin!

    https://www.ads-software.com/plugins/petfinder-listings/

Viewing 15 replies - 1 through 15 (of 24 total)
  • Thread Starter jewelsmac6

    (@jewelsmac6)

    Just wanted to check in and hope there might be some advice about how to fix this? Thank you in advance!

    Plugin Author bridgetwes

    (@bridgetwes)

    Hi,

    Petfinder returns pets with most recent addition last and does not provide a way to reorder the pets in the XML they return. I have to make some other updates and will see if there is a way to reorder the pets without stuffing them all in a new array and reordering that array. Petfinder said they were going to update their API early this year to add more features, but so far they have not gotten around to it.

    Thread Starter jewelsmac6

    (@jewelsmac6)

    Thank you very much for letting me know! I do hope there is a way to reorder the list, but I understand it might not be possible without Petfinder’s help. I will also reach out to Petfinder through my NPO account and see if I can help bring up the issue to them regarding the API. I will let you know what they say, if anything. Thanks again!

    Plugin Author bridgetwes

    (@bridgetwes)

    Thanks that would be great if you can ask Petfinder for an update on the new API. I use the shelter.getPets call and it has limited filtering and no ordering capabilities. If it could filter, it would make it much easier to add paging. I have to filter on my end so its impossible to know how many results I’ll actually end up displaying when I call the api function.

    I agree! We use the PetFinder plug in for our site: https://www.helpadogsmile.org/adopt/dogs/

    It’s awesome … I would LOVE the ability to put the most recent dogs at the top.

    Also … could it have a link with each profile that takes them back to that animal’s individual PetFinder listing?

    That would be great.

    THANK YOU!
    Josie

    Thread Starter jewelsmac6

    (@jewelsmac6)

    I emailed Petfinder through my NPO account over the weekend and just got the following response:
    ——
    An update to API is in the works, but there is no scheduled release date. You can periodically check https://www.petfinder.com/developers/api-docs , as new API information would be posted on that site once it’s available.

    I’m not sure if it works in the current API, but try sorting your results by using sort=Identifier+asc or sort=Identifier+desc

    ——-

    Does that help? Or not really? If it doesn’t help, I will reply back to them to ask for additional help.

    I also agree with Josie’s request. Is it possible to make the photo or the pet’s name clickable back to their profile page on Petfinder.com?

    Thanks again for developing such a useful plugin!
    Julie

    Hi Jewels,

    There is no built in filter for sort by date (as Bridget said), however, there are a few ways you can manipulate the ordering to your liking.

    #1
    Store an ID/Date pair in the database, where ID is the ID of the animal and Date is the date you first retrieved it from the API.

    If the entry does not exist, add the new entry. After you have scanned all the IDs, output the IDs in descending order “SELECT … ORDER BY DATE DESC”. Match the IDs with the entries retrieved by the API call and output accordingly.

    I want to stress that this method is inefficient.

    #2
    I suspect that the PET IDS are assigned in ascending order, with 1 being the first and 39842422 (just an example) being the most recent.

    If this is the case, then you can store all the IDs in an array, do arsort() which sorts from highest to lowest. Iterate through your new ID array and match the ID with the data retrieved from the API call and output accordingly.

    Please confirm/deny my suspicions by going to your Petfinder.com page and looking at the IDs of the pets (find it in URL).

    Good luck!

    Thread Starter jewelsmac6

    (@jewelsmac6)

    Looking at this now… what code do I add? To the petfinder-listings.php?

    I did a search for “sort” in the PHP file and didn’t see where to modify this. Thank you!

    I’m afraid it is not as simple as adding some code. This would require a decent amount of coding and a good understanding of the plugin’s code.

    You would need to:
    Do API Call
    Retrieve response XML
    Convert XML into Associative array using SimpleXML
    Sort associative array using ksort() or similar
    Match associative array values to xml values and replace in the plugin

    I would wait for the petfinder API to build this feature. Unless your employer desperately wants this and is prepared to devote a lot of resources.

    Thread Starter jewelsmac6

    (@jewelsmac6)

    Thank you very much for your response! I was hoping it could be added to the PHP or JS files, but because I am not a professional programmer/developer, I cannot do this on my own. If I hear anything back from Petfinder about this feature, I will reply to this post again to let you know.

    As you suggested, I will also wait for this with the API update. Petfinder did reply to me a few weeks ago, posted above, but it sounds like their suggestion still wont work?
    https://www.ads-software.com/support/topic/list-new-additions-first?replies=9#post-4615246

    anyone have any updates on sorting capability?
    Currently, it appears to be sorted by Petfinder System ID in ascending order. The latest pet added has the largest value, and thus shows last.

    Thanks,
    Gary

    Hi all,

    I’ve semi-confirmed my suspicions about the pet id order (latest has largest value).

    Using this assumption, I modified some code to display the highest pet id first, so the most recent will be on top. Perhaps this can be incorporated into next release?

    In petfinder-listings.php:
    See pastebin line 452 : https://pastebin.com/updzcbSN

    Modified code:

    $numpets = count($pets)-1;
    for( $inc = $numpets; $inc >= 0; $inc-- ){
    
    $dog = $pets[$inc];

    Tested on local version, seems to work.

    Good luck!

    I’m the admin for our Petfinder ID and when I look at the data for the pets, I think it can only be the Petfinder System ID (i.e. pet id that shows up in the URL for a specific pet on Petfinder) that this API’s results are sorted by.
    I’ve tried modifying birth date, date added, case in names, adding special characters in names to check ascii sort, and nothing is changed.
    The Petfinder System ID for the pet has to be a unique ID and probably a Primary key for them, so it makes sense their function call returns in that order. The index their query uses is mostly likely sorted by that key and hence that is the order the results are returned in.

    thanks,
    gary

    Gary,

    Did you try the snippet out yet? I’m curious to see if it works.

    Hi Rawrzors,
    I just tried pasting into where I thought it went, judging by what you posted. No pets were listed after I tried it.
    But my petfinder-listings.php looked different than what you had at the link. I have the latest version of the plugin which was rolled out recently, so maybe the source I have is different than yours if you haven’t updated yet.

    I placed the code right above: $bigfile = “”;
    But in my source, right above $bigfile = “”;
    Is: foreach( $pets as $dog ){

    that’s different than what you have. I’m not experienced enough to go messing around with it to try to figure it out ??

    btw, I emailed petfinder’s api support to get an update. Got a response today:
    “We are working on a new API system, hopefully to be reeled this year, but I don’t have any other information available at this time regarding sorting arguments.”

    thanks,
    gary

Viewing 15 replies - 1 through 15 (of 24 total)
  • The topic ‘List new additions first’ is closed to new replies.