WordPress.org

Forums

Petfinder Listings
[resolved] List new additions first (25 posts)

  1. jewelsmac6
    Member
    Posted 1 year ago #

    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: http://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!

    http://wordpress.org/plugins/petfinder-listings/

  2. jewelsmac6
    Member
    Posted 1 year ago #

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

  3. bridgetwes
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  4. jewelsmac6
    Member
    Posted 1 year ago #

    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!

  5. bridgetwes
    Member
    Plugin Author

    Posted 1 year ago #

    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.

  6. hungryherbivores
    Member
    Posted 1 year ago #

    I agree! We use the PetFinder plug in for our site: http://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

  7. jewelsmac6
    Member
    Posted 1 year ago #

    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 http://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

  8. rawrzors
    Member
    Posted 1 year ago #

    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!

  9. jewelsmac6
    Member
    Posted 1 year ago #

    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!

  10. rawrzors
    Member
    Posted 1 year ago #

    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.

  11. jewelsmac6
    Member
    Posted 1 year ago #

    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?
    http://wordpress.org/support/topic/list-new-additions-first?replies=9#post-4615246

  12. glura
    Member
    Posted 1 year ago #

    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

  13. rawrzors
    Member
    Posted 1 year ago #

    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 : http://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!

  14. glura
    Member
    Posted 1 year ago #

    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

  15. rawrzors
    Member
    Posted 1 year ago #

    Gary,

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

  16. glura
    Member
    Posted 1 year ago #

    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

  17. rawrzors
    Member
    Posted 1 year ago #

    Gary,

    Did you overwrite the foreach($pets as $dog){ and replace it with my snippet?

    I believe you are looking at the right lines of code.

    If that fails, post your .php file in pastebin and i'll take a look in the morning.

  18. glura
    Member
    Posted 1 year ago #

    I had commented out the foreach stmt what was there using /* */

    I pasted to http://pastebin.com/XGKrRP7F

    thank you,
    gar

  19. rawrzors
    Member
    Posted 1 year ago #

    It should be working if you replaced the foreach statement on line 227 with my snippet

  20. rawrzors
    Member
    Posted 1 year ago #

    I am currently using the latest version of the plugin. I took your code from pastebin and added my snippet. Tested and works on my end.

    Replace your .php with this and it should work.
    http://pastebin.com/0uYHkVMR

    Let me know how it goes.

  21. jewelsmac6
    Member
    Posted 1 year ago #

    Thank you everyone for your work on this! I also updated the plugin to version 1.0.10 and have added rawrzors's code above, and my most recent pets are now showing first. This looks great, thanks so much!!

  22. bridgetwes
    Member
    Plugin Author

    Posted 1 year ago #

    Thanks for helping everyone rawrzor! I just put up an update that allows sorting on newest, last_updated or name. That should give everyone the control they need. (It also fixed the missing large image which was caused by a change in Petfinder's XML.)

  23. jewelsmac6
    Member
    Posted 1 year ago #

    Just a quick note - I just updated the plugin to version 1.0.12 and the names are still not clickable. I had to manually add that code back in, which will be lost again with the next plugin update. Is it possible to incorporate this feature into the next update? Or add a "more info" hyperlink to each animal? Something along those lines in order for people to click on the pet in order to see more information. Otherwise, it's just the photos without any details.

    For quick reference, Rawrzors code to make the names clickable is below, thank you again Rawrzors!!
    $output_buffer .= "<div class=\"dog\"><div class=\"name\"><a href=\"http://www.petfinder.com/petdetail/".$dog->id."\" name=\"" . $dog->id . "\" target=\"_blank\">". $dog->name . "</a></div>";

    Thank you!!

  24. bridgetwes
    Member
    Plugin Author

    Posted 1 year ago #

    Hi Jewels,

    Aren't you seeing the pet's description along with the photos? Everything on petfinder should be listed on your own website with the petfinder plugin. If you aren't seeing the description and pet details, let me know and I'll take a look at your website.

    Adding a link to Petfinder isn't high on my list, truthfully. The purpose of the plugin is to keep users on your website so you can educate them about your particular shelter or rescue and the pets you have available. I don't think adding a link to Petfinder adds any value - and can be confusing to the visitor since you are sending them off to another site with the same information.

    So convince me or point out what benefit linking to Petfinder adds and I'll think about it.

    You can remove your plugin from my updates by changing the information at the top of the petfinder-listings.php file, and maybe readme.txt. The information at the top of those pages is how updates are communicated with your site. Change that info and you won't get update alerts or links when I update the plugin. I've done this with plugins I've modified for my own purposes and it works well.

  25. jewelsmac6
    Member
    Posted 1 year ago #

    Hi bridgetwes,

    Thanks for the reply! I agree with everything you're saying. The reason I requested the pet's name be linked to their petfinder profile page (thank you again rawrzors for your help there!) is to keep only the photos on the homepage (no description in order to cut down real estate on the page and tease people into clicking for more info), and secondly so people can easily see the "adopt me" button and fill in the form for that pet. Here is my homepage if you'd like to see it:
    http://heartsherd.com

    Right now, I have in my shortcode include_info="no" but it still shows the pet's written story. I only wanted the photos and age/sex/size to display. I didn't want the pet's full story to show because the text takes up so much space on the homepage, thus creating a very long scrolling box. Not a great user experience. So this is why I wanted the running list of pets names/photos only, and then the pet's name to click through to their profile page on petfinder with the "adopt me" button. So any help there as to why the shortcode isn't working is appreciated!

    But I just read through this thread and liked this approach. So what I did was add a link to the top of my petfinder list so people don't have to search for the Adoption/Foster Application Form.
    http://wordpress.org/support/topic/links-from-within-the-shortcode

    If you have any other suggestions, I am open to your ideas!

    Thank you very much for this plugin! I do like to keep it up to date as you make improvements and it has been a huge help to list our pets from petfinder on our website like this!

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Petfinder Listings
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic