Home Forums General Issues Prepopulate Custom Fields Based off of Taxonomy Reply To: Prepopulate Custom Fields Based off of Taxonomy

  • Hi James,

    Thanks for getting back to me!

    So writing custom Javascript is something I’m definitely comfortable with doing the only issue that I have with that approach is I don’t like the idea of generating that HTML within JS and then injecting it onto the page. In my mind this is what would have to happen if I went the JS way.

    – User selects Taxonomy term from Select
    – I make AJAX call to PHP with the Taxonomy Term.
    – PHP makes call to DB to get latest 4 entities that have that Taxonomy Term and send back.
    – Consume response from PHP and create HTML in JS and render HTML onto the page.

    The last step is a problem because from what I can see in the HTML on the admin page there is a lot of dynamic ids and attributes that are used that I wouldn’t have on my HTML because I have no way of knowing whats needed. Maybe you have some more insight there that I’m missing.

    If I go the second route you suggested that seems a little more doable. My only question there is on the save_post hook I would need to make a call to DB to get the latest 4 entities and then create fields not update fields. Not sure if I can make a call to DB in that hook and also not sure if update_fields() is what I need. So I took a look into the docs more and saw add_row(). Do you think this would be better for what I’m trying to do?